Python Forum
Flask files running order - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Flask files running order (/thread-30899.html)



Flask files running order - TomasAm - Nov-12-2020

I have blog.py inside my blog folder for Flask application.

blog.py contains:
from app import app
Inside blog folder there is app folder and it contains __init__ with the following code:
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager

app = Flask(__name__)
app.config.from_object(Config)
login = LoginManager(app)
login.login_view = 'login'
db = SQLAlchemy(app)
migrate = Migrate(app, db)

from app import routes, models
As I understand from here blog.py takes ONLY app = Flask(__name__) ?
Meanwhile routes.py inside app folder may import more of these like db, login etc.

So to sum up I would be pleased to know if this is the correct order of the app files running:
*export FLASK_APP=blog.py runs blog.py file inside blog folder
*blog.py runs app variable from __init__ inside app folder
*then who runs routes.py file?

#routes.py
from flask import render_template, flash, redirect
from app import app
from app.forms import LoginForm
from flask_login import current_user, login_user
from app.models import User
from flask_login import logout_user
from flask_login import login_required
from flask import request
from werkzeug.urls import url_parse
from flask_login import logout_user

@app.route('/')
Or in general how are the whole files we create from Flask application coming together?