django - 我在使用 mod_wsgi 与 Apache 设置 Django 时遇到问题
问题描述
我已经尝试了很多,感觉我被卡住了,没有得到任何地方 Apache 给出的错误是
ModuleNotFoundError:没有名为“wearpretty.settings”的模块
我正在使用 python 3.6、Django2.1、apache2、libapache2-mod-wsgi-py3
以下是正在使用的文件。
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "wearpretty.settings"
application = get_wsgi_application()
虚拟主机配置文件
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName lhwearpretty.com
ServerAlias www.lhwearpretty.com
DocumentRoot /var/www/myprojects/wearpretty/wearpretty/wearpretty
<Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty
WSGIProcessGroup lhwearpretty.com
WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
Alias /static/ /var/www/myprojects/wearpretty/wearpretty/static/
<Directory /var/www/myprojects/wearpretty/wearpretty/static>
Require all granted
</Directory>
</VirtualHost>
解决方案
您的DocumentRoot应该是一个文件夹(减去 1 /wearpretty
),并且WSGIDaemonProcess中的 python-path var应该是一个文件夹(加 1 ):它们必须指向您的 Django 项目根目录。/wearpretty
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName lhwearpretty.com
ServerAlias www.lhwearpretty.com
DocumentRoot /var/www/myprojects/wearpretty/wearpretty
<Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty/wearpretty
WSGIProcessGroup lhwearpretty.com
WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
Alias /static /var/www/myprojects/wearpretty/wearpretty/static/
<Directory /var/www/myprojects/wearpretty/wearpretty/static>
Require all granted
</Directory>
</VirtualHost>
另外,我建议添加此目录节点:
<Directory /var/www/myprojects/wearpretty/wearpretty>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
推荐阅读
- python - 按天递增日期并输入新字符串
- javascript - HERE API 不会加载地图 - H.Map (Argument #0 null)
- c - VBO 究竟如何保留其内容?
- java - 在 jsoup 中使用 h2 解析相关数据
- javascript - 允许 Vue2 选择组件为选择选项接收任何数组
- html - 为什么在 HTML 中定义的图像没有加载?
- java - 使用柱状转置的错误排序
- jquery - 如何将查询结果合并为新列?
- alfresco - 如何在 Alfresco Share Controls 中添加新的 JS 库?
- javascript - 在Js中如何对数组进行操作还要考虑数组可能只是一个元素