繁体   English   中英

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

[英]Using the URLconf defined in lec3.urls, Django tried these URL patterns, in this order: admin/ hello/ The empty path didn't match any of these

这些是我为创建 wepapp 而编写的主要代码,但我收到了这个 404 错误,所以请帮助我的 hello urls.py

from django.urls import path

from hello import views

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

我的 urls.py

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

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

我的观点.py

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

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

看起来您正在index使用

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

尝试

http://127.0.0.1:8000/hello

反而。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM