python - Passing strings to Django URL in template -


i think simple, can't figure out life of me why these urls aren't matching.

my template code looks this:

<form action="{% url 'view_record' "facility_report" %}" method="post"> {% csrf_token %}  {{ form }}  <input type="submit" value="view report" name='view' label="submit">  </form> 

the url supposed match line in url conf:

url(r'^view_record/((?p<report_type>.+)/)?$', views.view_record, name='view_record'), 

what missing here? won't match , of other questions regarding 5 years ago when engine seems have been lot more picky formatting.

exception type: noreversematch @ /view_record/ exception value: reverse 'view_record' arguments '('facility_report',)' , keyword arguments '{}' not found. 1 pattern(s) tried: ['view_record/((?p<report_type>(.*))/)?$'] 

the outer group in ((?p<report_type>.+)/)? capturing group. django's url reversal can't handle nested capturing groups, catch outer group possible argument. since first argument not end in /, pattern doesn't match , noreversematch thrown.

you can change outer group non-capturing group, , django pick inner group capturing group. way, argument not have contain /, inner group replaced, , outer group used as-is.

to create non-capturing group, start group ?::

url(r'^view_record/(?:(?p<report_type>.+)/)?$', views.view_record, name='view_record'), 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -