【发布时间】:2020-07-26 03:06:31
【问题描述】:
我尝试在 apache2 上创建一个新的 django 项目,但出现 404 错误。 这是我所做的。
-在/home/ubuntu/django目录下,输入
django-admin startproject proj
-编辑 proj/proj/wsgi.py 如下。
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
sys.path.append('/home/ubuntu/django/proj');
sys.path.append('/home/ubuntu/django/proj/proj');
application = get_wsgi_application()
-编辑 proj/proj/settings.py 中的 ALLOWED_HOSTS 如下。
ALLOWED_HOSTS = ['example.com']
-编辑/etc/apache2/conf-available/wsgi.conf如下。
WSGIScriptAlias /proj /home/ubuntu/django/proj/proj/wsgi.py
WSGIPythonPath /home/ubuntu/django/proj
<Directory /home/ubuntu>
Require all granted
</Directory>
<Directory /home/ubuntu/proj/proj>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
-重启apache2为
/etc/init.d/apache2 restart
-访问http://example.com/proj,然后得到如下404错误。
Page not found (404)
Request Method: GET
Request URL: http://example.com/proj/
Using the URLconf defined in proj.urls, Django tried these URL patterns, in this order:
admin/
The empty path didn't match any of these.
我的环境如下。
- Ubuntu 18.04 LTS (AWS)
- Apache/2.4.29
- Python 3.6.9
- Django 3.0.5
我该如何解决这个 404 错误?
【问题讨论】:
标签: django python-3.x apache2 mod-wsgi