How to segregate python pages in flask and mysql? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to segregate python pages in flask and mysql?

I am beginner working on flask and mysql all my python code are in one single page in app.py but i no that this is not the correct way in flask and sqlalchamey they divide the pages into init.py, views.py, auth.py, main.py .writing python code in single page may leads to problem in loading pages.Is there any ways to divide py pages using flask and mysql. writing code in different python page try to import that pages in app.py ,worked on add_url_rule nothing is working.My project is little bit big so try to divide pages.

17th Jan 2024, 5:37 AM
Jayashree M
3 Answers
+ 2
Jayashree M Listen, In a Flask application with MySQL, you can segregate your Python code by using separate files for different components. This typically involves organizing code related to routes in  app.py , database models in  models.py , and route handlers in  views.py .
17th Jan 2024, 6:18 AM
SATYAM MORNINGSTAR
SATYAM MORNINGSTAR - avatar
+ 2
A͢J, Help This Man Because I Don't Know.
17th Jan 2024, 10:27 AM
SATYAM MORNINGSTAR
SATYAM MORNINGSTAR - avatar
+ 1
Yes writing different routes in views.py is working but my every routes require database data after writing mysql details in views it shows me error , getting routes data from views and take blueprints is working but each routes requires mysql data,so i posted question here
17th Jan 2024, 6:32 AM
Jayashree M