How do you specify a named URL pattern in Django if you need to pass it a template variable? My template contains the following URL:
# templates/welcome.html
# Link to template that shows all members near member with this uid
<a href="{% url 'show-members-near' %}uid={{ uid }}">Show members near you</a>
My top-level URLconf file contains the following pattern which points to the application-specific url file:
# conf/urls.py
urlpatterns = patterns('',
...
url(r'^members/', include('apps.members.urls')),
...
)
Here is my application-specific url file:
# app/members/url.py
url(r'^near/(?P<uid>\d{1,})/$',
'show_members',
{'template': 'show_members.html'},
name='show-members-near'),
This is the error I get:
NoReverseMatch at /personal_profile/welcome/
Reverse for 'show-members-near' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['members/near/(?P<uid>\\d{1})/$']
I tried to insert a keyword argument like this but it didn't work:
<a href="{% url 'show-members-near' uid={{ uid }} %}">Show members near you</a>
After doing some research, everything I read seemed to indicate that the keyword argument should be passed the way I did it up above. What I'm trying to do is the equivalent of the following which does work:
<a href="/members/near/{{ uid }}/">See who's here</a>
How do I specify a keyword argument? I didn't see anything that addresses this situation in the Django docs (although I might have missed it).
Thanks!