-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split functionality into modules #10
Comments
I split the functionality into modules, but what I don't understand is the part where I have to register them with the Flask app? They import |
If you keep the route decorators on the view functions, you don't have to register them (again). Often times you want to separate the view functions (what they do, how they are implemented) and their route (is it If you want to stay with the route decorator that's fine 👍 I just wanted to bring this to your attention. |
Oh okay. That makes sense. Thank you! |
Just today I added a little Flask server to my project and this is a perfect example of a situation where you can not use See how the Flask Just noted that while implementing it and thought you may be interested :) |
That's an interesting take on it. Thank you for explaining! 😄 |
Currently you have all the "business logic" in the
pegasus.py
file. What you normally do is split logical parts into their own modules. For exampleviews.py
module for all of your views (functions that run on a specific route endpoint) and anerrorhandlers.py
module for custom error handlers. You then hoist yourapp
in the__init__.py
file, import both modules and register them with your Flask app like this:The logical structure can be something similar to:
views.py
for all of your view functions,models.py
for classes that abstract away entities and how you store and query them in your database, and then other modules as needs be, e.g. adecorators.py
with helpers such as http://flask.pocoo.org/docs/0.10/patterns/viewdecorators/#templating-decorator (good time to learn about decorators!).Your
view.py
then could look similar to this:The text was updated successfully, but these errors were encountered: