G
G
Gourii2020-07-29 09:22:11
Django
Gourii, 2020-07-29 09:22:11

How to run a Django test project?

Hello!
Help please deal with the problem. There is a test project on Django, written according to some kind of manual. In test mode, everything starts and works.


***@ServerUbuntu:/var/www/mysite$ python3 manage.py runserver 10.8.0.1:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 29, 2020 - 08:47:42
Django version 2.2.14, using settings 'mysite.settings'
Starting development server at 10.8.0.1:8000
Quit the server with CONTROL-C.

Test mode:

5f210e70313b4683870213.png

But on Apache refuses to work. It can be seen from the logs that Apache runs the project using Python 2.7, and it needs 3rd or higher for normal operation. I tried to use a virtual environment, but it did not work out. How to force Apache to use Python version 3 for Django?

Error log:


***@ServerUbuntu:/var/log/apache2$ cat test3.log
[Wed Jul 29 08:40:23.292988 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] mod_wsgi (pid=8219): Target WSGI script '/var/www/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Jul 29 08:40:23.293123 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] mod_wsgi (pid=8219): Exception occurred processing WSGI script '/var/www/mysite/mysite/wsgi.py'.
[Wed Jul 29 08:40:23.293196 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] Traceback (most recent call last):
[Wed Jul 29 08:40:23.293264 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] File "/var/www/mysite/mysite/wsgi.py", line 4, in
[Wed Jul 29 08:40:23.293453 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] from django.core.wsgi import get_wsgi_application
[Wed Jul 29 08:40:23.293616 2020] [wsgi:error] [pid 8219] [client 10.8.0.4:64417] ImportError: No module named django.core.wsgi


/var/www/mysite/mysite/wsgi.py


***@ServerUbuntu:/var/log/apache2$ cat /var/www/mysite/mysite/wsgi.py
#!/usr/bin/env python3
import os, sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()


/etc/apache2/sites-available/000-default.conf


***@ServerUbuntu:/etc/apache2/sites-available$ cat 000-default.conf
<аVirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin admin.mysite.com
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /mysite /var/www/mysite
ErrorLog ${APACHE_LOG_DIR}/test3.log
<а/VirtualHost>
<аDirectory /var/www/mysite>
Order allow,deny
<а/Directory>


If you explicitly specify the path to Python in the Apache settings, then the result is as follows:

WSGIPythonHome /usr/local/lib/python3.5/dist-packages

5f21146e6df52499335580.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-29
@pyHammer

Gourii don't use Apache for this.
As for the virtual environment, here is the command to create it under python 3

virtualenv --no-site-packages --python=/usr/bin/python3 --prompt="(<project_name>)" <venv_name>

then you activate the environment and install gunicorn.
There are a lot of instructions for running nginx/gunicorn/Django on the Internet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question