Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLASK_APP variable isn't behaving as specified. #1970

Closed
noahcgreen opened this issue Jul 31, 2016 · 2 comments
Closed

FLASK_APP variable isn't behaving as specified. #1970

noahcgreen opened this issue Jul 31, 2016 · 2 comments

Comments

@noahcgreen
Copy link

The docs on the FLASK_APP variable state that

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".

@wgwz
Copy link
Contributor

wgwz commented Aug 7, 2016

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?

@noahcgreen
Copy link
Author

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!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants