Actually that might not work entirely, since your settings file will be
imported before the environment variables are copied over.

Instead you can lazily construct the django application on the first
request:

django_application = None

def application(environ, start_response):
    global django_application

    if django_application is None:
        # pass the WSGI environment variables on through to os.environ
        for var in env_variables_to_pass:
            os.environ[var] = environ.get(var, '')
        django_application = get_wsgi_application()

    return django_application(environ, start_response)

And yes, using a real environment variable solution is better. You can only
use WSGI environment for configuration during requests - not during
background processes such as management commands or background task queues
like Celery.

On Thu, 23 Apr 2020 at 15:00, Brian Tiemann <greenintog...@gmail.com> wrote:

> Beautiful. That does the trick. Thank you!
>
> And I certainly can see there's plenty of other approaches such as
> envparse or django-environ that I could be using, that keeps the vars out
> of my Apache config. Quick fix and a slighly longer better fix. This'll
> change how I do all my new projects from now on, plus retroactively for all
> the ones I used this approach with...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/97ea9ad1-7f9d-4648-8eb5-c3b8a42f479b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/97ea9ad1-7f9d-4648-8eb5-c3b8a42f479b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1Ti0inv_5xrc-OSJJSKPWCzvpp0qy7OeB%2B2JpOy1iwBA%40mail.gmail.com.

Reply via email to