Applications are made to be deployed. At some point during development you will need to think about the environment in which your application will ...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Jake,
I am a noob, trying to learn python along with good practices. Now the queries: The official python-dotenv documentation talks about using the dotenv alongside settings module (python-settings). The load_dotenv() function is also recommended to be put in settings.py. Unable to wrap my head around the following:
Thanks.
you can write inside using this
This is a great way to store API keys or other secrets so that theyβre not hard coded into your application!
Absolutely! Thanks for pointing that out. A .env file is a great way to work on a project with those kinds of security concerns in mind without the overhead of storing that information as a system environment variable on your computer.
Tnx for article! But there is one important caveat here: if you use Linux for example you can not use env names like
HOME
orNAME
orLOGNAME
. Because your app variables from.env
file (in currently working directory) will be overwritten by the global (from Linux).For example: in case you put in
.env
NAME=Michale
and you are logged in as user Daniel, inside your python scriptos.getenv("NAME")
will return Daniel instead of Michael. And most probably this is not something you want in your app....I guess there is different ways to resolve this, but most obvious one for me is to avoid this names entirely and to use some convention like
APP_NAME
orAPP_HOME_DIR
....Really nice writeup! I was just playing around with Python-DotEnv today.
Thanks! While it is a very lightweight package, thereβs more to it than I initially realized. Iβve primarily used it as described in the article but it does have features that allow for a few other use cases.
no pip install needed ?
pip install python-dotenv
If you use an Anaconda environment, you can set environment variables in the Conda environment without needing .env files!
my python script and .env file are in the same folder but somehow it is unable to read the file unless I specify the path.
Thank you so much!
Great!!!
Thanks, had a chance to try this today
It helped me a lot, thank you!