Comments (7)
Hm, I wonder if you could simply move the issue from the server (Apache) into the application (wsgi.py). Couldn't you just use envdir's Python API to load the environment variables before Django initializes completely?
See my blog software for an example: https://github.com/jezdez/jezdez.com/blob/dc7f7bc765b68e285a0e68f026b74c20aaf0e4c6/jezdez/wsgi.py#L22
Note: the used envdir.read
function is deprecated, use the envdir.open
instead: http://envdir.readthedocs.org/en/latest/api.html#envdir.open
Would that help fix the issue in cookiecutter-django, @pydanny?
from django-configurations.
Well, I think as long as you do not want to control any settings from your virtualhost via environemt variables, you are fine. But what about the following situation:
You have 2 envdir directories, one for debugging, one for production. You now have 2 options to load these programmatically:
a) In your manage.py or wsgi.py you want to control der envdir directory to load based on a environment variable. This is basically what you are doing here:
path = parent / 'envs' / os.environ.get('ENVDIR', 'dev')
But this requires that you are able to set this variable in the virtualhost (or somehwere else) and retrieve this value in python somehow. Because otherwise you will always end upt with 'dev'. This wouled be possible based on the approach in SO, but Graham does not like it.
b) you have a dev_manage.py / prod_manage.py as well as a dev_wsgi.py /prod_wsgi.py and control the envdir directory to be opend this way. But this somehow is completely against the idea of django-configuraitons and envdir.
Is there an option c)?
from django-configurations.
So just checking where we are: do we agree on the problem? If so, would be be willing to get the Apache Env variables from the request (other than recommended by Graham)
from django-configurations.
I've just added support for .env files, a different strategy for storing environment variables. See 01e3f58
The bottom line is:
Set the DOTENV
setting in your class to a file path that you want to let django-configurations read. They can differ per environment class of course. See http://ddollar.github.io/foreman/#ENVIRONMENT for more info. This is also used on Heroku as .env
files during local development with Foreman.
from django-configurations.
Since I see Apache, mod_wsgi, and environment variables are the title of this issue, it behooves me to point out a downstream issue that was opened for cookiecutter-django: cookiecutter/cookiecutter-django#160
from django-configurations.
@pydanny Thanks!
I'm a bit sad to see this issue being dragged between that many projects and that some people involved seem to be passive-aggressive about it. That said, it seems to be an issue for some users stuck on Apache so I'll take a look at how to best document it. Probably with the idea of having separate wsgi/*.py
files to set the environment variables for each environment. It's an additional chore for the users but that's the gist of my experience with Apache anyway.
from django-configurations.
@jezdez, Sending you a private email.
from django-configurations.
Related Issues (20)
- Improve Dotenv usage to avoid basic issues HOT 1
- Use the 'furo' theme for Sphinx documentation
- Improve code blocks in documentation
- Release minor version 2.4.1 HOT 3
- 2.4.1: pytest is failing HOT 2
- Replace deprecated imp module with importlib HOT 4
- How can this be used with `django.setup()` HOT 2
- Make magical importing optional
- <frozen importlib._bootstrap>:1049: ImportWarning: ConfigurationImporter.find_spec() not found; falling back to find_module() HOT 4
- "STATICFILES_STORAGE/STORAGES are mutually exclusive" on Django>=4.2
- WSGI application loaded twice unexpectedly
- Release 2.4.2 is not on PyPI HOT 9
- Update Python and Django supported versions
- Add support for Python 3.12 HOT 1
- DeprecationWarning for USE_DEPRECATED_PYTZ, CSRF_COOKIE_MASKED, USE_L10N
- Broken link in `Configuration.load_dotenv` docstring HOT 1
- Add Django 5.0 classifier
- Publish version 2.5.1 on PyPi HOT 2
- Values not working in DATABASES dictionary and values.Value returning Value instance type instead of a str HOT 1
- DOTENV - Using environ_name strange behevior HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-configurations.