Django教程第1部分:错误的路径导致(404)

问题描述 投票:1回答:1

我已经设置了django教程的第1部分,并且在尝试访问民意调查应用时收到以下“页面未找到(404)”错误:

Error Message

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添加到混合中时,我开始遇到问题。这是我的代码:

原/ urls.py:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
  path('polls/', include('polls.urls')),
  path('admin/', admin.site.urls),
]

民调/ urls.py

from django.urls import path
from . import views

urlpatterns = [
  path('', views.index, name='index'),
]    

民调/ 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),
]

我错过了什么吗?


在我将Django配置为使用Apache作为Web服务器之后,包括非默认的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>
django apache mod-wsgi
1个回答
1
投票

Daniel Roseman建议我包含我的Apache配置。当我在这篇文章中添加配置参数时,我看到了虚拟主机配置中的错误。 WSGIScriptAlias是罪魁祸首。

当前:

WSGIScriptAlias /polls /var/local/www/proto/proto/wsgi.py

应该:

WSGIScriptAlias / /var/local/www/proto/proto/wsgi.py

完成配置更改后,教程按预期工作。

有时只需要有人看着你的肩膀。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.