我是靠谱客的博主 寒冷微笑,这篇文章主要介绍django.urls.exceptions.NoReverseMatch: Reverse for 'myyear' with arguments '(100 0,)' not found.,现在分享给大家,希望可以做个参考。

django.urls.exceptions.NoReverseMatch: Reverse for 'myyear' with arguments '(100
0,)' not found. 1 pattern(s) tried: ['bblog/(?P<year>[0-9]{4}/)']

templates

<body>
<h1> ni hao </h1>
<div><a href="bblog/2018/">2018 old archive</a></div>
<div><a href="{% url 'bblog:myyear' 1000 %}">2018 archive</a></div>
</body>

view 

def myyear(request, year):
# return HttpResponse('hello world!'+str(year))
return render(request, 'bblog/myyear.html')

报错 函数myyear 缺失实参, 其原因是在写url正则表达式的时候出了问题, 错误代码如下:

urlpatterns = [
re_path('(?P<year>[0-9]{4}/)', views.myyear, name='myyear'),

在上面 正则表达式中,错把斜杠放在小括号里。  移到括号外面就可以了  

 

 

最后

以上就是寒冷微笑最近收集整理的关于django.urls.exceptions.NoReverseMatch: Reverse for 'myyear' with arguments '(100 0,)' not found.的全部内容,更多相关django.urls.exceptions.NoReverseMatch:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部