【问题标题】:The current path, didn't match any of these - Django当前路径,与这些都不匹配 - Django
【发布时间】:2019-04-19 17:14:54
【问题描述】:

页面http://127.0.0.1:8000/category.html/ 抛出 404, 说

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

admin/
^ [name='index']
^ category [name='category']
The current path, category.html/, didn't match any of these.

ddblog2/ddblog2/urls.py如下:

from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^', include('blog.urls')),
]

ddblog2/blog/urls.py如下:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'), 
    path('category/', views.category, name = 'category')
]

ddblog2/blog/views.py:

from django.shortcuts import render

def index(request):
    return render(request, 'index.html', {})

def category(request):
    return render(request, 'category.html', {})

“博客”已添加到 INSTALLED_APPS

我该如何纠正这个错误?

【问题讨论】:

  • URL 格式是category/ 而不是category.html/。另外,为什么不使用path('blog/', include('blog.urls')), 代替r'^' 来代替r'^'
  • @Rajan 是的,我的错误。明白了。

标签: django


【解决方案1】:

您需要将 html 添加到 ddblog2/blog/templates/blog/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 2019-12-27
    • 2019-05-18
    • 2018-12-01
    • 2018-08-18
    • 2020-08-02
    相关资源
    最近更新 更多