python - Django Reverse URL Lookup Template Error -
i'm having bit of trouble reverse url lookups in django.
from template:
<form action="{% url 'blog:save' post.slug %}" method="post">
from urls:
url(r'^post/(?p<slug>\w+)/save/$', views.save, name='save'),
from views:
def save(request, slug): return httpresponse("not saved.")
error i'm getting:
exception type: noreversematch exception value: reverse 'save' arguments '(u'',)' , keyword arguments '{}' not found.
post.slug
variable in template empty string, url requires 1 or more characters (\w+
). django builds /post//save/
, url invalid.
if need save new post no slug, use optional subpattern in url:
r'^post/(?:(?p<slug>\w+)/)?save/'
Comments
Post a Comment