Search posts, tags, users, and pages
Why do we need to write the variable in uppercase in .env file? Is it required?
No, it's a naming convention.
Keep in mind (if you want to do it differently) that Windows is case-insensitive with global variables. Linux and Mac OS are not. Meaning that if you have a variable called 'Language' and you use os.environ['language'], it will work if you run it on Windows but not on MacOS or Linux
Lou Sorry, I don't understand!
Isn't all this is being done by python? why operating system is deciding this behaviour?
(I think it should be case-sensitive because python is a case-sensitive programming language)
You're right about python being case-sensitive.
But these are environment variables, not Python variables. What makes environment variables so easy to work with is that the variables you create in your .env file are saved onto your local OS. When you use os.environ you tell Python that it has to search on your OS for the needed variable, nothing more. Sounds very technical because it is.
Just remember that using uppercase for the variables in your .env file is the easiest way to not get complications if you want someone else to use your code.
Thanks Lou :)
I think I understand it now
Just to summarise:
Some developers came up with an idea to put all imp password/stuff in a file for security and name it as .env
and
this file will (and should) only be available on local machine and the main server (have to upload file seperately) to ensure safety of resources while sharing code
Finally, this article explain how to access those environment variables using python :]