[英]Django Url regex NoReverseMatch error
有这个html,我想在按下URL时将2个参数传递给一个函数:
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
url(r'^notification_htmlv2/update_status/([0-9]{4})/([0-9]{4})$', 'Notifications.views.updateStatus',
name="update-notify-status"),
views.py
def updateStatus(request,noteId,noteTile):
q=History.objects.filter(notification_id=noteId,title=noteTile).order_by('-id')[0]
当我启动程序时,出现错误“ NoReverseMatch”。 我按照这个例子: https : //docs.djangoproject.com/en/1.8/topics/http/urls/
url章节的反向解析
我打赌n.id
和n.title
匹配([0-9]{4})
。
您应该更新您的网址格式,以处理所有可能的id
和title
值。
就像是:
r'^notification_htmlv2/update_status/([0-9]+)/([a-zA-Z0-9]+)$'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.