【发布时间】:2019-03-24 14:42:01
【问题描述】:
我通过迁移添加了数据,现在在运行 migrate 和 makemigrations 之后
我尝试runserver 并且到处都有 NoReverseMatch 错误。
看看这个错误:
NoReverseMatch at /blog/
Reverse for 'blog_post_detail' with keyword
arguments '{'year': 2008, 'month': 9, 'slug': 'django-10-released'}'
not found. 1 pattern(s) tried:
['(?P<year>\\d{4}/)^(?P<month>\\d{1,2}/)^(?P<slug>\\w+)/$']
在迁移中它看起来像这样:
POSTS = [
{
"title": "Django 1.0 Release",
"slug": "django-10-released",
"pub_date": date(2008, 9, 3),
"startups": [],
"tags": ["django", "python", "web"],
"text": "THE Web Framework.",
},]
这是实际的 urlpattern:
re_path (r'^(?P<year>\d{4}/)'
r'^(?P<month>\d{1,2}/)'
r'^(?P<slug>\w+)/$',post_detail,name='blog_post_detail'),
同样,每个模板都有同样的问题......
【问题讨论】:
-
请不要使用
>来缩进代码或错误消息。它隐藏了尖括号,因此它显示['(?P\d{4}/)^(?P\d{1,2}/)^(?P\w+)/$']而不是['(?P<year>\\d{4}/)^(?P<month>\\d{1,2}/)^(?P<slug>\\w+)/$']。
标签: python django python-3.x django-templates django-migrations