Okay, I'll do that, but I'm behind in a few things, so it might take me a while. I'll demo today. It's not very interesting.
Sure. It's an outgrowth of what I hoped would be helpful pedagogically, but which has had mixed results. I sometimes have forms (in template files) that look like this:
Then, in app.py, I would have:
The pedagogical idea was to make the connection between the two
endpoints more explicit, and to put the relevant code all
in app.py. I think some people found that helpful, and
others didn't.
In real life, we would almost always hard-code the value of
the ACTION attribute:
The latter. Flask routes the request to our Python function, which then renders the response. There might not be an HTML file at all! That's how our first examples were.
The template files like F-strings on steroids.
Great question. If your handler function doesn't support GET, Flask will render an error, something like "no handler for GET of /foo". That's fine.
Alternatively, your handler can support GET and create your own custom response, which might just be a different phrasing of that error message, say using flashing, maybe along with a redirect to a better endpoint.
No, there's really no difference. It doesn't matter where the template for the form is located.
All that matters is that it ends up in the rendered page, with a valid METHOD and ACTION.
What a great question! In principle, yes, though in practice most teams do not do this.
However, there are some tricky bits because all the Python
files would need to share the same app global variable.
One option is to have app.py contain:
And then the teammates files look like this:
Which is deeply weird, because each module is importing the other. But it does work.
A conceptually easier approach is to put all
the app.route() endpoints into the
main app.py file, but with references to
Since the team should agree on the endpoints and keep those stable, this approach has some advantages.
Note, the above code is from memory and is just for answering this question conceptually. I haven't double-checked the syntax and such.