django 2.1
和
python 3.6
我正在讨论一个问题
other people
在过去的几年中遇到过。
views.py
:
def blog_list_by_cat(request, cat_id, cat_name):
...
def blog_list_by_genre(request, genre_id, genre_name):
...
这是我的
urls.py
urlpatterns = [
path('', views.index, name='index'),
re_path(r'^blog/(?P<blog_id>\d+)/(?P<slug>[^/]+)/?$', views.single_blog, name='single_blog'),
re_path(r'^blog-list/(?P<cat_id>\d+)/(?P<cat_name>[^/]+)/?$', views.blog_list_by_cat, name='blog_list_by_cat'),
path('blog-list/latest/', views.blog_latest, name='blog_latest'),
re_path(r'^blog-list/genre/(?P<genre_id>\d+)/(?P<genre_name>[^/]+)/?$', views.blog_list_by_genre, name='blog_list_by_genre'),
]
在我的模板中,当我调用这些链接时,此链接可以正常工作:
{% for cat in cat_list %}
<a class="dropdown-item" href="{% url 'blog_list_by_cat' cat_id=cat.id cat_name=cat.cat %}">{{ cat.cat }}</a>
{% endfor %}
当此操作在同一模板中引发错误时:
{% for genre in genre_list %}
<li><a class="dropdown-item" href="{% url 'blog_list_by_genre' genre_id=genre.id genre_name=genre.title %}">{{ genre.title }}</a></li>
{% endfor %}
这是全部错误:
异常值:对于带有关键字参数“{'genre\u id'”的“blog\u list\u by\u genre”则相反:
['blog-list/genre/(?P\d+)/(?P[^/]+)/?$']
如你所见,我正在使用
named urls