Django 1.9 Apache Error Import Django.core.handlers.wsgi Importerror: No Module Named 'django'
I try to deploy my Django project to apache. But I getting an error 500response. And in logs I getting information that Django is missing. I'm using virtualenvto run this project.
Solution 1:
I got a few apache servers with django and it was pain when i set up them. So minimum working configuration with static files is:
WSGIPythonPath /home/mariusz/Dokumenty/Projekty/zalien
<VirtualHost *:80>
WSGIScriptAlias / /home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py
<Directory /home/mariusz/Dokumenty/Projekty/zalien/zalien>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# Django static files, here you must specify your own path's
Alias /static/ /var/www/djangointra/static/
<Directory"/var/www/djangointra/static">
Require all granted
</Directory>
</VirtualHost>
Also you should not modify your wsgi.py
files in your django projects. Apache configuration is enough to start your web-server.
EDIT: wsgi.py
"""
WSGI config for djago_api project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djago_api.settings")
application = get_wsgi_application()
Solution 2:
Never too late. May be this will help someone else. I had the same error and it is resolved by 2 changes. Below is the working config. I had Django 1.10, Python 3.5 and Apache 2.4
wsgi.pi
import os, sys, site
from django.core.wsgi import get_wsgi_application
site.addsitedir("/home/mariusz/Dokumenty/Projekt/envy/lib/python3.5/site-packages")
sys.path.append("/home/mariusz/Dokumenty/Projekty/zalien")
sys.path.append("/home/mariusz/Dokumenty/Projekty/zalien/zalien")
activate_this = "/home/mariusz/Dokumenty/Projekty/envy/bin/activate_this.py"withopen(activate_this) as f:
code = compile(f.read(), activate_this, "exec")
exec(code, dict(__file__=activate_this))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zalien.settings")
application = get_wsgi_application()
Apache test.conf
<VirtualHost *:80>
WSGIDaemonProcess zalien processes=2 threads=12 python-home=/home/mariusz/Dokumenty/Projekt/envy/ python-path=/home/mariusz/Dokumenty/Projekty/zalien:/home/mariusz/Dokumenty/Projekt/envy//lib/python3.5/site-packages
WSGIProcessGroup zalien
WSGIScriptAlias / /home/mariusz/Dokumenty/Projekty/zalien/wsgi.py process-group=zalien
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/ /var/www/html/static/
<Directory /var/www/html/static/>
Require all granted
</Directory>
<Directory /home/mariusz/Dokumenty/Projekty/zalien>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Post a Comment for "Django 1.9 Apache Error Import Django.core.handlers.wsgi Importerror: No Module Named 'django'"