我正在学习本教程。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.
如有任何协助,我们将不胜感激。
执行以下更改来自:
path('firstapp', include('firstapp.urls')),
至:
path('firstapp/', include('firstapp.urls')),