Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django dev server request.META has all my env vars

Tags:

python

django

Why do I see all my environment variables in request.META when using the dev server?

like image 335
lajarre Avatar asked Mar 27 '14 12:03

lajarre


People also ask

How to add environment variables in Django?

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.

What are the different environments in Django?

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.

How do you pass state in Django?

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.

Is there a way to share default Django environment settings with VCS?

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


1 Answers

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.

like image 172
uprightcarrion Avatar answered Sep 23 '22 04:09

uprightcarrion