我才刚开始学Django。
我在另一个名为“djangoTest”的应用程序中创建了一个名为“flavo”的简单web子应用程序
当我运行http://127.0.0.1:8000/flavo
它可以正确显示
Hello, World!
然后,当我运行http://127.0.0.1:8000/flavo/a
时,它应该显示
Hello, a!
但我得到的却是:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/flavo/a
Using the URLconf defined in testDjango.urls, Django tried these URL patterns, in this order:
admin/
flavo [name='index0']
flavo a [name='a']
The current path, flavo/a, didn’t match any of these.
在testDjango/hello/views.py中
from django.http import HttpResponse
from django.shortcuts import render
def index0(request):
return HttpResponse("Hello, world!")
def a(request):
return HttpResponse("Hello, a!")
在testDjango/flavo/url/py中
from django.urls import path
from . import views
urlpatterns = [
path("", views.index0, name="index0"),
path("a", views.a, name="a"),
]
我唯一更改的另一个文件是testDjango/testDjango/url.py“
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('flavo', include("flavo.urls")),
]
我不明白为什么我不能访问http://127.0.0.1:8000/flavo/a
添加“/”
像这样
相关问题 更多 >
编程相关推荐