Which file is typically used to start the Flask application?
medium
A. config.py
B. app/__init__.py
C. app/routes.py
D. run.py
Solution
Step 1: Identify the purpose of run.py
In Flask projects, run.py is commonly used as the entry point to start the app server.
Step 2: Differentiate from other files
config.py holds settings, __init__.py initializes app, and routes.py defines routes, but none start the server directly.
Final Answer:
run.py -> Option D
Quick Check:
run.py starts Flask app [OK]
Hint: run.py usually starts the Flask app server [OK]
Common Mistakes:
Trying to run config.py to start app
Running __init__.py directly
Running routes.py as main file
4. You have this run.py file:
from app import app
if __name__ == '__main__':
app.run(debug=true)
But running python run.py gives an ImportError: cannot import name 'app'. What is the likely cause?
medium
A. run.py is missing the Flask import statement
B. The 'app' variable is not defined in app/__init__.py
C. The templates folder is missing
D. Debug mode cannot be set in run.py
Solution
Step 1: Understand the import error
The error means app is not found inside the app package's __init__.py.
Step 2: Check app/__init__.py for app variable
Usually, app = Flask(__name__) is defined in __init__.py. If missing, import fails.
Final Answer:
The 'app' variable is not defined in app/__init__.py -> Option B
Quick Check:
app must be defined in __init__.py [OK]
Hint: Ensure app variable is defined in __init__.py before importing [OK]
Common Mistakes:
Assuming missing Flask import causes this error
Thinking templates folder affects imports
Believing debug mode setting causes import error
5. You want to organize a Flask project with multiple blueprints for different features. Which structure best supports this while following Flask conventions?