[Django] #22722: runserver - read environment variables from a .env file

184 views
Skip to first unread message

Django

unread,
May 28, 2014, 4:38:14 PM5/28/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------+--------------------
Reporter: kermit | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Just bumped into [https://github.com/joke2k/django-environ this cool
project] to adhere to the 12-factor app philosophy where server-specific
settings are read from environment variables. I'm wondering if there's an
easy way to get ./manage.py runserver to also read environment variables
from a .env file, so that I don't have to resort to some shell/.bashrc
trickery on every server? For example
[https://github.com/nickstenning/honcho honcho] supports this, but then I
don't have the server auto-refresh whenever I edit the source.

--
Ticket URL: <https://code.djangoproject.com/ticket/22722>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 28, 2014, 5:21:04 PM5/28/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------+--------------------------------------

Reporter: kermit | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

It's not clear to me why you need this. `runserver` shouldn't be used in
production and I don't think we're going to add more features to it, but
I'll leave the ticket open in case you'd like to elaborate further.

--
Ticket URL: <https://code.djangoproject.com/ticket/22722#comment:1>

Django

unread,
May 28, 2014, 5:41:49 PM5/28/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------+--------------------------------------

Reporter: kermit | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by kermit):

OK, yeah, I think I might not have been too clear. So,
[http://12factor.net/config the 12-factor app clause] is that on servers,
you should be able to control the relevant configuration using environment
variables, as it's easy to manage this using e.g. ansible, salt or the
heroku cli. The .env file is used on a local dev machine to not have to
set up these environment variables in your .bashrc for every project. This
is already supported by process launchers such as foreman and honcho
([https://honcho.readthedocs.org/en/latest/using_procfiles.html
#environment-files relevant honcho] and
[http://ddollar.github.io/foreman/#ENVIRONMENT foreman docs]), but while
developing we probably want to use ./manage.py runserver, as it auto-
refreshes on code changes. Now, I'm suggesting a -e <envfile> option (and
implicitly reading variables from a .env file if it's present) that would
set the relevant environment variables for the launched process, to be
able to keep the same workflow with runserver too.

--
Ticket URL: <https://code.djangoproject.com/ticket/22722#comment:2>

Django

unread,
May 28, 2014, 7:30:32 PM5/28/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------------+-------------------------------------
Reporter: kermit | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.6
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* component: Uncategorized => Core (Management commands)
* type: Uncategorized => New feature


Comment:

It makes sense, but couldn't you do something like add some logic in your
development settings file to parse and set the variables? It may not be
the most elegant solution, but I'm hesitant to add more logic to
`runserver` for this purpose.

In the long run, we've thought about replacing runserver with something
like gunicorn (#21978) since as a web framework, our focus shouldn't be on
building web servers.

I did notice that gunicorn has [http://gunicorn-
docs.readthedocs.org/en/latest/settings.html#raw-env an option for passing
environment variables] (although not reading them from a config, it
appears).

Anyway, that's just my 2 cents, we'll see what others think.

--
Ticket URL: <https://code.djangoproject.com/ticket/22722#comment:3>

Django

unread,
May 29, 2014, 3:44:42 AM5/29/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------------+-------------------------------------
Reporter: kermit | Owner: nobody

Type: New feature | Status: new
Component: Core (Management | Version: 1.6
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

I'd rather see this as a complementary Django application (subclassing
runserver). Not everyone adhere to the 12-factor app philosophy, and I'm
not fond of adding new code in Django each time a new trend is in the air
(no offense intended). I'm personally rather on the minimalist side of
things.

--
Ticket URL: <https://code.djangoproject.com/ticket/22722#comment:4>

Django

unread,
May 29, 2014, 9:02:53 AM5/29/14
to django-...@googlegroups.com
#22722: runserver - read environment variables from a .env file
-------------------------------------+-------------------------------------
Reporter: kermit | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: 1.6
commands) | Resolution: wontfix

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* status: new => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/22722#comment:5>

Reply all
Reply to author
Forward
0 new messages