Django使用lec3.URL中定义的URLconf尝试了这些URL模式,顺序如下:admin/hello/空路径与其中任何一个都不匹配

2024-09-30 10:27:29 发布

您现在位置:Python中文网/ 问答频道 /正文

这些是我为创建wepapp而编写的主要代码,但我收到了404错误,请提供帮助 my hello URL.py

from django.urls import path

from hello import views

urlpatterns = [
   path("", views.index, name="index")
]

我的URL.py

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

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

我的观点

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
def index(request):
    return HttpResponse("hello, orld")

Tags: pathdjangofrompyimporturlhelloindex
1条回答
网友
1楼 · 发布于 2024-09-30 10:27:29

看起来您正试图使用访问index

http://127.0.0.1:8000/。这将不起作用,因为您的index包含在hello的url.py中,并且hello的url以hello/开头

试一试

http://127.0.0.1:8000/hello

相反

相关问题 更多 >

    热门问题