Ich muss Django Entwicklungs- und Produktionseinstellungen teilen. Ich entschied, dass, wenn USKOVTASK_PROD
Variable gesetzt ist, dann App Produktionseinstellungen verwenden sollte. Ich las this Artikel und versuchte es zu tun.Django + mod_wsgi. Set OS Umgebungsvariable von Apache SetEnv
Meine Schnipsel:
/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 des Teil:
import os
if 'USKOVTASK_PROD' in os.environ:
from settings_prod import *
else:
from settings_dev import *
Aber es importiert immer settings_dev Einstellungen. Warum?
Können Sie debuggen und überprüfen, ob USKOVTASK_PROD wirklich in os.environ setzt? Sie können dafür einen einfachen Ausdruck platzieren. – iamkhush
@iamkhush USKOVTASK_PROD ist in os.enivron, wenn ich es in 'wsgi.py' drucken, aber nicht in' settings.py' – michaeluskov
Können Sie, wenn die Anweisung überprüfen „wenn‚USKOVTASK_PROD‘in environ“ wahr ist, durch Druck setzen, nachdem sie . – iamkhush