You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django教程开发首个视图时遭遇404页面错误求助

Django教程《Writing your first Django app, part 1》中polls页面404问题

完成《Writing your first Django app, part 1》的“Write your first view”环节时,已严格按照教程要求配置相关文件。访问http://127.0.0.1:8000/时能正常显示“The install worked successfully! Congratulations!”,但访问http://localhost:8000/polls/时出现404错误:

Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls/, didn’t match any of these.

按照教程预期,此时应显示“Hello, world. You're at the polls index”。相关文件内容如下:

polls/views.py

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

mysite/urls.py

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

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

已在Stack Overflow及YouTube查找解决方案但未成功,该配置在另一台电脑上可正常运行,仅我的笔记本出现此问题。

内容的提问来源于stack exchange,提问作者KamilO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 14:50:45