【发布时间】:2020-11-22 23:47:26
【问题描述】:
我在互联网上尝试了很多解决方案并尝试了很多 URL 模式,但都没有正常工作。这是我的 urls.py
urlpatterns = [
re_path(r'^category/(?P<cat>\w+)/$',views.categoryPage,name="category"),
re_path(r'^',views.home,name="index"),
]
html 链接
<a class="nav-link" href='{% url "category" cat=mobiles %}'>Mobiles & Tablets <i class="fa fa-angle-down iconClr" aria-hidden="true"></i></a>
和views.py
def categoryPage(request,cat):
return render(request,'amazonApp/categoryItem.html',context={'category_name':cat})
浏览器出错
NoReverseMatch at /
Reverse for 'category' with keyword arguments '{'cat': ''}' not found. 1 pattern(s) tried:
['category/<cat>']
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 3.0.8
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'category' with keyword arguments '{'cat': ''}' not found. 1 pattern(s) tried:
['category/<cat>']
Exception Location: C:\Users\DELL\Django\amazon_affiliate\env\lib\site-
packages\django\urls\resolvers.py in _reverse_with_prefix, line 677
Python Executable:
C:\Users\DELL\Django\amazon_affiliate\env\Scripts\python.exe
Python Version: 3.8.5
]
我尝试了一种 Django Documentation 解决方案,但没有帮助。
【问题讨论】:
标签: python python-3.x django django-views django-templates