【问题标题】:Page not Found (404) in django在 django 中找不到页面(404)
【发布时间】:2020-02-22 00:53:16
【问题描述】:

我正在使用 django 我收到此错误 Page not Found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ 使用 VibezT.urls 中定义的 URLconf,Django 按此顺序尝试了这些 URL 模式

  1. 音乐/
  2. 管理员/

空路径与其中任何一个都不匹配。

VibezT\urls.py

from django.contrib import admin

from django.urls import include, path

urlpatterns =[

    path('music/', include('music.urls')),

    path('admin/', admin.site.urls),

]

对于音乐 URL,我有此代码

音乐\urls.py

from django.urls import path

from . import views  

urlpattern = [

    path(r'^$',/  views.index, name='index')

]

对于视图我有这个代码

from django.http import HttpResponse

def index(request):

    return HttpResponse("Hello World")

【问题讨论】:

  • 你这里有流浪/path(r'^$',/ views.index, name='index')吗?

标签: python django


【解决方案1】:

您尚未在代码中为 / 定义 URL。你的代码是为music/定义的

您需要前往http://127.0.0.1:8000/music/ 找到您的视图。

另外,如果您使用路径,我不知道您为什么要像这样构建您的 URL。 path(r'^$',/ views.index, name='index')

只需将其替换为:

path('', views.index, name='index'),

在你的音乐中\urls.py

【讨论】:

  • 我去了127.0.0.1:8000/music,使用 VibezT.urls 中定义的 URLconf 显示这些错误,Django 尝试了这些 URL 模式,顺序如下: 1. music/^$ [name='index' ] 2. admin/ 当前路径music/ 与其中任何一个都不匹配
  • 我也不知道你为什么要这样构造你的东西` " path(r'^$',/views.index, name='index') "`
  • 其实是在看教程视频
猜你喜欢
  • 2016-08-01
  • 2016-08-01
  • 2015-10-22
  • 2014-03-20
  • 2020-10-27
  • 2019-07-21
  • 1970-01-01
  • 2020-04-14
  • 2016-03-31
相关资源
最近更新 更多