我尝试在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 as
/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.
我的环境如下。
我该如何解决此404错误?
我尝试在apache2上创建一个新的django项目,但出现404错误。这是我所做的。 -在/ home / ubuntu / django目录中,键入django-admin startproject proj-将proj / proj / wsgi.py编辑为...
您的urls.py文件中有'/ admin'吗?您可能还需要将apache2设置从/ home / ubuntu / proj / proj更改为/ home / ubuntu / django / proj / proj