You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In that imported file the name of the app needs to be called app or optionally be specified after a colon. For instance mymodule:application would tell it to use the application object in the mymodule.py file.
However, creating the following script (run.py):
from flask import Flask
webapp = Flask(__name__)
setting FLASK_APP=run.py:webapp, and running flask run gives me an ImportError:
Traceback (most recent call last):
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 156, in __call__
self._flush_bg_loading_exception()
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 144, in _flush_bg_loading_exception
reraise(*exc_info)
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 133, in _load_app
self._load_unlocked()
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 148, in _load_unlocked
self._app = rv = self.loader()
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 209, in load_app
rv = locate_app(self.app_import_path)
File "/Users/me/app/venv/lib/python3.5/site-packages/flask/cli.py", line 89, in locate_app
__import__(module)
ImportError: No module named 'run'
Interestingly, using FLASK_APP=run.py actually works even with the app named "webapp". So while I'm not sure how much of this is error on my part vs. error on flask's, the docs are wrong in saying that the Flask object needs to be named "app".
The text was updated successfully, but these errors were encountered:
This works for me: export FLASK_APP=run or export FLASK_APP=run:webapp and python -m flask run. Or export FLASK_APP=run.py and then flask run. It looks like the base issue is #1847. But it is fixed by #1872?
Reading the links, seems the issue is that the package needs to be installed for the CLI to work right. It would be nice if it that wasn't necessary, but I'm closing this because it's a duplicate of #1847. Thanks!
The docs on the FLASK_APP variable state that
However, creating the following script (run.py):
setting
FLASK_APP=run.py:webapp
, and runningflask run
gives me an ImportError:Interestingly, using
FLASK_APP=run.py
actually works even with the app named "webapp". So while I'm not sure how much of this is error on my part vs. error on flask's, the docs are wrong in saying that the Flask object needs to be named "app".The text was updated successfully, but these errors were encountered: