Forums

Getting page routes into file other than: /home/Flask04/mysite/flask_app.py?

I've been following the tutorials to get pages to show by putting them in this file with the format:

@app.route("/test1")
def hello_world():
    return "Welcome to the test page1"

sure, this is easy to do, but how to put the new routes into a new file, as this main app file is quickly getting bogged down with code?

[edit by admin: formatting]

deleted post

@app.route("/test1") def hello_world(): return "Welcome to the test page1"

and how to post code on here without it looking like above? thanks

I've followed the tutorial which adds a basic calculator to the main flask_app.py file (do_calculation)

however,how to add another script without getting rid of the calculator? (as the new script will need a new route)?

To post code that is formatted, select it and then click the "code" icon in the set of buttons above the editor -- it looks like this:

101
010

This will indent the selected text by four spaces, which means it will be formatted as code. Unfortunately this won't work if the code is the first thing in your comment, so you need to put something above it.

Regarding splitting your Flask app into multiple files, check out this part of the Flask docs

ok, thanks, I'll give that a try