Issue
TL;DR
I don't want to export
my variables every time I log on. I want them in my config.
From the docs
Using the environment variables as described above is recommended. While it is possible to set ENV and DEBUG in your config or code, this is strongly discouraged.
How do I do it anyway? How is it 'possible'?
MORE - What I've Tried
I have a flask.cfg
with FLASK_ENV='development'
. I run flask run
and I get development
printed. But the production server has already started. It ignores the following:
app.config.from_pyfile("flask.cfg")
print(f"{app.config['ENV']}") => development
This is in a personal project of no consequence. That's why I am ignoring best practices for convenience.
Solution
What about this: install python-dotenv package, create a .flaskenv file in your project root folder and add, for example, this:
FLASK_APP=app.py (or whatever you named it)
FLASK_ENV=development (or production)
Save. Do flask run.
Answered By - no use for a name
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.