【发布时间】:2015-07-10 04:13:05
【问题描述】:
有这个 html,我想在按下该 url 时将 2 个参数传递给函数:
html页面
{% 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.title 可能是一个不会被 ([0-9]{4}) 匹配的字符串,你需要这样的东西:[\w-]+