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.cli.NoAppException raised when .env/.flaskenv exists in parent directory and python-dotenv installed #3561

Closed
greyli opened this issue Apr 7, 2020 · 3 comments
Labels
Milestone

Comments

@greyli
Copy link
Member

greyli commented Apr 7, 2020

Description

With this minimal application:

# app.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, Flask!'

and this file structure:

- project
    - .env
    - hello
        - app.py

When executing flask run inside the hello folder, you will get a NoAppException error, although the app.py is present in the current work directory. By the current implementation, since .env is in the top-level directory, Flask will change the current work directory to the directory that contains the .env file, so it can't find the app.py.

Steps to reproduce:

$ git clone https://github.com/greyli/flask-env-test
$ cd flask-env-test
$ pip install -r requirements.txt  # or just pip install flask[dotenv]
$ cd hello
$ flask run
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

I think it will be a bit confused when the user accidentally put a .env or .flaskenv in the top-level directory. Can we drop this change directory behavior (#3560)?

Environment

  • Python version: 3.6.8
  • Flask version: 1.1.2
  • Werkzeug version: 1.0.1
@davidism
Copy link
Member

davidism commented Apr 7, 2020

Also reported in #3535, which I closed for a larger discussion in #3108 (comment). I'm not opposed to it, would be good to hear from @jab.

@davidism davidism added the cli label Apr 7, 2020
@jab
Copy link
Member

jab commented Apr 13, 2020

Sorry for the delay and thank you for the ping, @davidism. Responded in #3560 (comment).

@davidism davidism added this to the 2.0.0 milestone Apr 13, 2020
@jab
Copy link
Member

jab commented Jul 18, 2020

Should now be resolved via #3560.

@jab jab closed this as completed Jul 18, 2020
@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
Projects
None yet
Development

No branches or pull requests

3 participants