Django + mod_wsgi. Set OS environment-variable vom Apache SetEnv

Muss ich split Django ' s Entwicklung und Fertigung Einstellungen. Ich entschied, dass wenn USKOVTASK_PROD variable gesetzt ist, dann sollte die app Produktion verwenden Einstellungen. Ich lese diese Artikel und versucht, es zu tun.

Meine snippets:

/etc/apache2/sites-enabled/uskovtask.conf:

<VirtualHost *:80>

ServerName uskovtask.*.com
ServerAlias uskovtask.*.com
DocumentRoot /mnt/ebs/uskovtask


Alias /static /mnt/ebs/uskovtask/static/
<Directory /mnt/ebs/uskovtask/static>
    Require all granted
</Directory>

#WSGIPythonPath /mnt/ebs/uskovtask
WSGIDaemonProcess uskovtask.*.com python-path=/mnt/ebs/uskovtask:/usr/lib/python2.7/site-packages
WSGIProcessGroup uskovtask.*.com
WSGIScriptAlias / /mnt/ebs/uskovtask/uskovtask/wsgi.py
SetEnv USKOVTASK_PROD 1


<Directory /mnt/ebs/uskovtask/uskovtask>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

</VirtualHost>

wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "uskovtask.settings")

from django.core.wsgi import get_wsgi_application

_application = get_wsgi_application()

def application(environ, start_response):
    if 'USKOVTASK_PROD' in environ:
        os.environ.setdefault('USKOVTASK_PROD', environ['USKOVTASK_PROD'])
    return _application(environ, start_response)

settings.py's Teil:

import os

if 'USKOVTASK_PROD' in os.environ:
    from settings_prod import *
else:
    from settings_dev import *

Aber es immer Importe settings_dev Einstellungen. Warum?

Können Sie Debuggen und überprüfen, ob USKOVTASK_PROD wirklich fest in os.environ ? Sie können eine einfache drucken für, die.
USKOVTASK_PROD ist in os.enivron, wenn ich drucken Sie es in wsgi.py, aber nicht in settings.py
Können Sie überprüfen, ob die Aussage "wenn 'USKOVTASK_PROD" in environ" true Legend drucken, nachdem es.
es ist Falsch
Ok, dann ist klar, dass das problem mit der apache-conf-Datei keine Einstellungen die variable korrekt.

InformationsquelleAutor michaeluskov | 2014-11-17

Schreibe einen Kommentar