Home > OS >  How to determine flask_app name
How to determine flask_app name

Time:08-15

Sorry if this is a bit basic but wanted to validate what my flask_app name would be that I set in my .env file when running locally.

I run my app using a wsgi.py file in root with the following contents:

from app import create_app, db

application = create_app()

if __name__ == '__main__':
   application.run()

However I then have a app/init.py

import os
from config import Config
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

def create_app(config_class=Config):

   app = Flask(__name__)
        app.config.from_object(config_class)
 #not sure if i mucked this up
db.init_app(app)

from app.main import main_blueprint

      app.register_blueprint(main_blueprint)

return app

Which I run with flask run. Therefore is my app name “app” or “application” or even something else?

CodePudding user response:

You want flask_app variable to be the name of the file which runs the app, so for you in your .env file it looks like you should have:

FLASK_APP = run.py

where run.py is the name of the file containing the first block of code in your question, assuming that your .env file is also in your root folder, let me know if that helps.

  • Related