如何避免我的第一个应用出现页面 404 错误

How to avoid Page 404 Error on my first app

我正在学习本教程。 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>')

这是我的 App urls 页面代码

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')),