[英]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.