简体   繁体   中英

Django Url regex NoReverseMatch error

Have this html, that i want to pass 2 arguments to a function when that url is pressed:

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]

When i start the program it gives an error of "NoReverseMatch". Im following this example: https://docs.djangoproject.com/en/1.8/topics/http/urls/

reverse resolution of url's chapter

I bet neither n.id nor n.title matches ([0-9]{4}) .

You should update your url pattern to handle any possible id and title values.

Something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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