Существует много способов развертывания Django, но я не знаю простого способа: -)
Для всех способов вам нужна хотя бы одна вещь: веб-сервер.
Обычные веб-серверыApache2 и nginx.
Я предполагаю, что вы используете сервер на основе Debian (например, Ubuntu).
Если вы выбираете apache2, установите apache с помощью:
sudo apt install apache2 libapache2-mod-wsgi-py3
Создайте файл с информацией о хостах.
/ etc / apache2 / sites-available / foo.conf
<VirtualHost *:80>
# This is name based virtual hosting. So place an appropriate server name
# here. Example: django.devsrv.local
ServerName {{ project_name }}.com
ServerAlias www.{{ project_name }}.com
# This alias makes serving static files possible.
# Please note, that this is geared to our settings/common.py
# In production environment, you will propably adjust this!
#Alias /static/ {{ project_directory }}/static_root/
#<Directory {{ project_directory }}/static_root>
# Options -Indexes
# Order deny,allow
# Allow from all
#</Directory>
# This alias makes serving media files possible.
# Please note, that this is geared to our settings/common.py
# In production environment, you will propably adjust this!
#Alias /media/ {{ project_directory }}/media/
#<Directory {{ project_directory }}/media>
# Options -Indexes
# Order deny,allow
# Allow from all
#</Directory>
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / {{ project_directory }}/{{ project_name }}/wsgi.py
# PROCESS_NAME specifies a distinct name of this process
# see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
# PATH/TO/PROJECT_ROOT is the full path to your project's root directory,
# containing your project files
# PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full
# path to its directory.
# Generally you must specify the path to Python's site-packages.
WSGIDaemonProcess {{ project_name }} threads=1 python-path={{ project_directory }}/:{{ path_to_virtualenv}}/lib/python{{ python_version }}/site-packages/
# PROCESS_GROUP specifies a distinct name for the process group
# see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup
WSGIProcessGroup {{ project_name }}
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/{{ project_name }}_error.log
CustomLog ${APACHE_LOG_DIR}/{{ project_name }}_access.log combined
</VirtualHost>
Заменить:
- {{имя_проекта}} с именем проекта
- {{project_directory}} с путем к каталогу вашего проекта
- {{path_to_virtualenv}} с путем к вашему virtualenv
- {{python_version}} с pythonversion вашего virtualenv
Запустите команды bash:
sudo a2ensite foo.conf
sudo service apache2 restart
Если у вас есть статические файлы, которые не работают, убедитесь, что вынастроил его правильно в settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"), ]
, затем отредактируйте ваш foo.conf и перезапустите apache снова.