Python 为什么我在/处获得NoReserverMatch?

Python 为什么我在/处获得NoReserverMatch?,python,django,Python,Django,我是Python新手,正在尝试开发一个简单的博客应用程序。在尝试规范url时,我得到了NoReverseMatch at/error。尝试了不同的解决方案来解决这个问题,但我得到了django旧版本的帮助。请帮助我更新Django版本的解决方案 错误: 未找到带参数的“post_details”(2020、'08、'15、'indian software industry')的反面。尝试了1种模式:[“blog/(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P\[-\w]+)/

我是Python新手,正在尝试开发一个简单的博客应用程序。在尝试规范url时,我得到了NoReverseMatch at/error。尝试了不同的解决方案来解决这个问题,但我得到了django旧版本的帮助。请帮助我更新Django版本的解决方案

错误: 未找到带参数的“post_details”(2020、'08、'15、'indian software industry')的反面。尝试了1种模式:[“blog/(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P\[-\w]+)/$”]

这是我的URL.py

from django.contrib import admin
from django.urls import path,re_path
from blog import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.post_list_view),
    re_path(r'^blog/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>\[-\w]+)/$',
    views.post_detail_view,name='post_details'),
这是我的post_list.html

{%extends 'blog/base.html'%}
{%block title_block%} Sentamil's Blog Home Page{%endblock%}
  {%block content%}
  <h1>My Blog</h1>
  {%for post in post_list%}

  <a href="{{post.get_absolute_url}}"> <h2>{{post.title}}</h2></a>
  <p id='date'>Published on {{post.publish}} by {{post.author|title}}</p>
  {{post.body|truncatewords:30|linebreaks}}
  {%endfor%}
  {%endblock%}
{%extends'blog/base.html%}
{%block title_block%}森塔米尔的博客主页{%endblock%}
{%block content%}
我的博客
{post_list%}中的post为%

由{post.author | title}在{post.publish}上发布

{{post.body | truncatewords:30 | linebreaks}} {%endfor%} {%endblock%}
您在上一部分中犯了一个错误,应该是这样的

(?P<post>\[\w-]+)/$',
(?P\[\w-]+)/$”,

这是路由URL的旧方法

re_path(r'^blog/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>\[-\w]+)/$',
    views.post_detail_view,name='post_details'),
re_path(r'^blog/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>\[-\w]+)/$',
    views.post_detail_view,name='post_details'),
re_path('<int:year>/<int:month>/<int:day>/<slug:post>/',views.post_detail_view,name='post_details'),
def get_absolute_url(self):
 return reverse('blog:post_detail',
 args=[self.publish.year,
 self.publish.month,
self.publish.day, self.slug])