I have created a python web application in Django 2.0
using pipenv
virtualenv
Now, I have to host it on apache server. I have installed libapache2-mod-wsgi-py3
and python-setuptools
in the server.
The structure of my application is like
myapp_dir
|- myapp
|- settings
|- __init__.py
|- production.py
|- __init__.py
|- urls.py
|- wsgi.py
|- otherapp
|- templates
|- static_my_project
|- manage.py
|- Pipfile
|- Pipfile.lock
the path of the application to put on
/home/user/app.application.com/
I have moved all files to the directory and installed all dependencies from Pipfile
by running in the directory
pipenv install
This has created a virtualenv and installed all required modules and the path of pipenv --venv
gives
# pipenv --venv
/home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_
My VirtualHost
configuration looks like
ServerName app.application.com
ServerAlias app.application.com
ErrorLog /home/user/error.log
CustomLog /home/user/custom.log combined
Alias /static /home/user/app.application.com/static_my_project
<Directory /home/user/app.application.com/static_my_project>
Require all granted
</Directory>
<Directory /home/user/app.application.com/pricearbitrase>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/user/app.application.com/myapp/wsgi.py
VirtualInclude contains
<IfModule mod_wsgi>
WSGIPythonHome /home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_
</IfModule>
But on accessing http://app.application.com
it gives Internal server error
and the log file generated contains
[wsgi:error] [pid 60730] mod_wsgi (pid=60730): Target WSGI script '/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 60730] mod_wsgi (pid=60730): Exception occurred processing WSGI script '/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py'.
[wsgi:error] [pid 60730] Traceback (most recent call last):
[wsgi:error] [pid 60730] File "/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py", line 12, in <module>
[wsgi:error] [pid 60730] from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 60730] ImportError: No module named django.core.wsgi
Edit 2
app/wsgi.py
modified wsgi.py
file to activate virtual environment
activate_this = '/home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_/bin/activate_this.py'
exec(compile(open(activate_this,"rb").read(),activate_this, 'exec'), dict(__file__=activate_this))
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")
application = get_wsgi_application()
Also, ls -l /path_to_pipenv_venv/bin
gives
/bin
still same error – Septa/bin
? – SeptaWSGIPythonPath
(see the example in the Django docs), but that would cause issues loadingmyapp
, notdjango
. – OctetWSGIPythonPath
what will be the path of this configuration – Septa/bin
, restarted server. still getting same error – Septamanage.py
). – Octet/bin
didn’t help, I’m afraid I don’t have any other suggestions. Hope you manage to get it working. – Octet