0

I'm trying to set app.config['FLASK_ENV'] = 'development' but when I run the app it starts runs with default configs (production environment).

My code is as simple as possible:

from flask import Flask
app = Flask(__name__)
app.config['FLASK_ENV'] = 'development'

@app.route('/')
def hello_world():
    return 'Hello, World!'

I'm kind of frustrated with Flask at this point as growing from a single file app example to a more structured small app is not covered in documentation. Every single example I found goes from hello world to a full large app, which makes the learning kind of a pain.

NoneType
  • 140
  • 1
  • 9
  • 1
    You might get some guidance from the Flask Mega Tutorial (https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world"), which walks you through building a less-than-trivial app, starting from the basics. – Dave W. Smith Jun 08 '19 at 02:09

1 Answers1

2

It seems that you're setting configurations correctly, but from the Flask configuation docs, you won't be able to set the environment in the code.

The ENV and DEBUG config values are special because they may behave inconsistently if changed after the app has begun setting up. In order to set the environment and debug mode reliably, Flask uses environment variables.

You can run development mode by calling the following:

$ export FLASK_ENV=development
$ flask run

Or, the answer here has other alternatives to set environment variables for your flask application.

rohanphadte
  • 978
  • 6
  • 19
  • The actual issue is that OP sets `app.config['FLASK_ENV']` instead of `app.config['ENV']`. The part of the documentation that you quote does not apply to OP's example, because setup of an application refers to what happens on the first HTTP request. – Markus Unterwaditzer Jun 10 '19 at 15:09