我已经设置了django教程的第1部分,并在尝试访问民意测验应用程序时收到以下“找不到页面(404)”错误:
Page not found (404)
Request Method: GET
Request URL: http://proto.slc.venturedata.com/polls/
Raised by: polls.views.index
Using the URLconf defined in proto.urls, Django tried these URL patterns, in this order:
1. polls/
2. admin/
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
我正在使用Django 2.2,Python 3.7,Apache 2.4.6,mod-wsgi 4.6.5。
我能够使用内置的Web服务器来完成本教程,但是当我将Apache和mod-wsgi添加到组合中时,我开始遇到问题。这是我的代码:
proto / urls.py:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
polls / urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
polls / urls.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
在settings.py中唯一更改的是TIMEZONE。其他所有内容均设置为默认值。
似乎与url和路径匹配有关。我使用的网址(proto.slc.venturedata.com/polls/)应该与“ polls /”路径匹配,但错误消息指出该路径为空。
在实验中,我发现如果我通过用空路径替换'polls /'路径来修改proto / urls.py,则不会收到错误消息。
urlpatterns = [
path('', include('polls.urls')),
path('admin/', admin.site.urls),
]
我想念什么吗?
包括非默认的Apache配置,因为在我将Django配置为将Apache用作网络服务器后问题就开始出现。
ServerName 10.0.10.249:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
WSGIPythonPath /var/local/www/proto/
<VirtualHost *:80>
DocumentRoot "/var/local/www/proto"
ServerName proto.slc.venturedata.com
<Directory "/var/local/www/proto">
Require all granted
</Directory>
WSGIScriptAlias /polls /var/local/www/proto/proto/wsgi.py
</VirtualHost>
答案 0 :(得分:1)
Daniel Roseman建议我包括我的Apache配置。在向该帖子添加配置参数时,我看到了虚拟主机配置中的错误。 WSGIScriptAlias是元凶。
当前:
WSGIScriptAlias /polls /var/local/www/proto/proto/wsgi.py
应该是:
WSGIScriptAlias / /var/local/www/proto/proto/wsgi.py
更改配置后,本教程将按预期工作。
有时候,只是需要有人看着你的肩膀。