簡體   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