gpt4 book ai didi

Django page not found although everything seems okay(找不到Django页面,尽管一切似乎都正常)

转载 作者:bug小助手 更新时间:2023-10-27 21:07:11 27 4
gpt4 key购买 nike



I am new to Django and I am doing everything that is indicated in Django documentation but I can not figure out why it keeps saying Page Not Found

我是Django的新手,我正在做Django文档中指出的所有事情,但我不明白为什么它总是说Page Not Found


I tried changing the path or Debug=True to Debug=False but nothing interesting happened. It once worked but now it keeps saying Page Not Found.

我尝试将路径或Debug=True更改为Debug=False,但没有发生任何有趣的事情。它曾经有效,但现在它一直说找不到佩奇。


from django.urls import path

from . import views

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

this is urls.py mainpage

这是urls.py主页


from django.shortcuts import render


from django.http import HttpResponse


def index(request):
return HttpResponse("My first page")

this is views.py mainpage

这是views.py主页


from django.contrib import admin
from django.urls import path
from django.contrib import admin
from django.urls import include, path
urlpatterns = [

path("mainpage/", include("mainpage.urls")),
path('admin/', admin.site.urls),
]

```and this one is urls.py mysite

this is the result:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

mainpage/ mainpage/ [name='mainpage']
admin/
The current path, mainpage/, didn’t match any of these.

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
http://127.0.0.1:8000/mainpage/

更多回答

http://127.0.0.1:8000/mainpage/mainpage/ would work. In your urls.py you include mainpage.urls if the path starts with mainpage/. In mainpage.urls you check for mainpage/ again. Together this is mainpage/mainpage/.

Http://127.0.0.1:8000/mainpage/mainpage/会奏效的。如果路径以mainpage/开头,则在urls.py中包含mainpage.urls。在mainagee.urls中,您再次检查是否有MainPage/。总而言之,这就是MainPage/MainPage/。

优秀答案推荐

I think the way you have set it up the correct url would be mainpage/mainpage.

我认为你设置它的方式正确的网址将是主页/主页。


By having this code path("mainpage/", include("mainpage.urls")) in your project's urls all of your paths found in mainpage.urls will have mainpage/ on the beginning. By including mainpage/ again in the app urls you end up with mainpage/mainpage.

通过在项目的URL中包含此代码路径(“mainPage/”,Include(“mainpage.urls”)),您在mainagee.urls中找到的所有路径的开头都将是mainpage/。通过在应用程序URL中再次包含MainPage/,您最终得到的是MainPage/MainPage。


I hope this is the issue and helps.

我希望这就是问题所在,并有所帮助。


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com