【发布时间】:2018-09-18 01:30:10
【问题描述】:
Django 突然似乎没有正确处理 url。我再次使用投票视图和 urlsconf 再次遵循“编写你的第一个 Django 应用程序”的第 3 部分。它不工作。我错过了什么?
这是我的views.py:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
这是我的投票\urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
为什么不工作\urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
]
为什么不工作\settings.py:
INSTALLED_APPS = [
'polls',
这是我的投票应用程序的目录: 迁移 管理员.py 应用程序.py 模型.py 测试.py 网址.py 视图.py 初始化.py
我可以运行测试服务器:
Run 'python manage.py migrate' to apply them.
April 08, 2018 - 16:25:27
Django version 2.0.4, using settings 'whyitsnotworking.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[08/Apr/2018 16:25:33] "GET / HTTP/1.1" 200 16348
Not Found: /polls
[08/Apr/2018 16:25:39] "GET /polls HTTP/1.1" 404 1964
但是得到以下错误信息:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls
Using the URLconf defined in whyitsnotworking.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls, didn't match any of these.
【问题讨论】:
标签: python django django-views