【发布时间】:2020-06-13 04:19:55
【问题描述】:
我正在学习本教程。 https://www.youtube.com/watch?v=a48xeeo5Vnk
这是我的视图代码:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request):
return HttpResponse('<h1>This is our blog</h1>')
def about(request):
return HttpResponse('<h1>This is our About Page</h1>')
def next(request):
return HttpResponse('<h1>This is our next Page</h1>')
这是我的应用网址页面代码
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='blog-home'),
path('about/', views.about, name='blog-about'),
path('next/', views.next, name='blog-NEXT'),
]
这是我的主要项目 URL 代码
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('firstapp', include('firstapp.urls')),
path('admin/', admin.site.urls),
]
现在,当我仅使用单个视图(即默认页面'')尝试此操作时,它单独工作,代码中没有提及更多页面,但是当我添加更多视图时,它会给我一个 404 页面错误。我相信代码很好,应该可以工作,但不知何故它选择不这样做。
尝试了不同的浏览器,尝试了论坛,但没有。
这是错误。
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/firstapp/
Using the URLconf defined in first.urls, Django tried these URL patterns, in this order:
firstapp [name='blog-home']
firstapp about/ [name='blog-about']
firstapp next/ [name='blog-NEXT']
admin/
The current path, firstapp/, didn't match any of these.
任何帮助将不胜感激。
【问题讨论】:
-
remove firstapp from path('firstapp', include('firstapp.urls')),查看首页或者在firstapp后面加'/'
标签: python django http-status-code-404