-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
config option for "flask run" (e.g. --dotenv/-e) #3108
Comments
I think we might have to disagree about env vars to some degree. We did add support for python-dotenv to read a The issue I see with adding a config option is that it now dictates one way to configure the app that's not portable to how you'd be deploying to production. If users use this and then use mod_wsgi, for example, they'd have to read the config themselves anyway. It lends preference to I think you might be looking for a custom run command that's more appropriate to your (and probably others) use cases. That might be a good fit for an extension that you'd then install for each of your projects. The docs on Flask's CLI document how extensions can register commands automatically. For example, you could register a You could also create your own |
Thanks so much for the helpful reply, @davidism! I decided to embrace environment variables after all, in a very particular way. After deciding on dotenv as a configuration storage format, and finding Flask CLI's built-in dotenv support only able to get us part of the way there, here's what I did: I ended up subclassing Users implement a Since I also provide a If we add the constraint of merely improving Flask's existing dotenv support (in the case that dotenv is installed) to accept a similar Thanks again for the FlaskGroup tip and for your consideration! |
After discussion at the sprint, we're thinking of adding a |
Can we provide a environment var to load specify file? |
Set environment variable (key=value). Pass variables to the execution environment. Ex.: $ gunicorn -b 127.0.0.1:8000 --env FOO=1 test:app |
#3535 discusses being confused by Flask automatically changing the working directory to the directory containing the env file. I'm wondering if we should revisit that behavior, or how it would tie in with a |
FWIW I got here from #3535 after walking through an strace from another dev where the culprit was a stray .env file. Even if this is intentional it definitely was not easy to find as flask run just said it couldn't find the app. Running python ./myapp.py showed a |
The issue you linked is related but different, and is fixed in the next version. |
I've been doing some work on enabling It could be made an |
Would it make sense to allow passing a
--config/-c
option toflask run
, that would then be exposed to users somehow for subsequent passing to e.g.app.config.from_pyfile()
?(I'm imagining this done in a reusable way so that a "flask gunicorn" custom command (the likes of which I've already implemented) could accept and expose a
-c
value similarly, so that the app could be configured from this same provided path whether running in development or production.)This would reduce the dependence on an environment variable to specify this. Reason I ask is that many of the Flask users I'm supporting are allergic to environment variables for the reasons mentioned in #3095, and have been missing some way to pass a CLI option to
flask run
to help configure their apps. Thanks 😊The text was updated successfully, but these errors were encountered: