简体   繁体   English

Django Url正则表达式NoReverseMatch错误

[英]Django Url regex NoReverseMatch error

Have this html, that i want to pass 2 arguments to a function when that url is pressed: 有这个html,我想在按下URL时将2个参数传递给一个函数:

htmlpage htmlpage

{% for n in notifications %}
                    <li style="..."><b>{{ n.title }}</b> - {{ n.description }}
                    <a href="{% url 'update-notify-status' n.id n.title %}" >Don't show again</a>
{% endfor %}

urls.py urls.py

url(r'^notification_htmlv2/update_status/([0-9]{4})/([0-9]{4})$', 'Notifications.views.updateStatus',
                       name="update-notify-status"),

views.py views.py

def updateStatus(request,noteId,noteTile):
q=History.objects.filter(notification_id=noteId,title=noteTile).order_by('-id')[0]

When i start the program it gives an error of "NoReverseMatch". 当我启动程序时,出现错误“ NoReverseMatch”。 Im following this example: https://docs.djangoproject.com/en/1.8/topics/http/urls/ 我按照这个例子: https : //docs.djangoproject.com/en/1.8/topics/http/urls/

reverse resolution of url's chapter url章节的反向解析

I bet neither n.id nor n.title matches ([0-9]{4}) . 我打赌n.idn.title匹配([0-9]{4})

You should update your url pattern to handle any possible id and title values. 您应该更新您的网址格式,以处理所有可能的idtitle值。

Something like: 就像是:

r'^notification_htmlv2/update_status/([0-9]+)/([a-zA-Z0-9]+)$'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM