Why do I see all my environment variables in request.META when using the dev server?
Therefore Adding environment variables is a necessary step for any truly professional Django project. Create a .env file in the same directory where settings.py resides and add the following key-value pair inside the file. We will use django-environ for managing environment variables inside our project. So let’s install the package.
Usually, you have several environments: local, dev, ci, qa, staging, production, etc. Each environment can have its own specific settings (for example: DEBUG = True, more verbose logging, additional apps, some mocked data, etc). You need an approach that allows you to keep all these Django setting configurations.
Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function. Each view is responsible for returning an HttpResponse object.
settings_local.py is not in VCS, so you can lose some of your Django environment settings. The Django settings file is a Python code, so settings_local.py can have some non-obvious logic. You need to have settings_local.example (in VCS) to share the default configurations for developers. Separate settings file for each environment
I just ran into this as well which caught me by surprise, I thought my page was sending all my env variables to the server. I use the env to store credentials so I was concerned.
Any application running in your environment has access to your env variables, therefore the server has access to your env variables. Bottom line the browser is not sending all your env variables to the server. The request object is built on the server side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With