Reputation: 2347
I'm trying to use a named regular-expression group to pass a keyword arguments to a view.
I'm very new to using regular-expressions (and Django) and keep getting a NoReverseMatch error.
In my template has a table with the following:
<td><a href="{% url profile player.user %}" data-toggle="modal" data-target="#profile"><i class="icon-forward"></i></a></td>
The URL that corresponds to "{% url profile player.user %}" is:
url(r'^profile/(?P<players_username>\w)/$', profile_page, name='profile'),
Also I'm not sure if "\w" was correct for this regex. Ideally I it could receive any character.
And my view "profile_page" is:
@login_required
def profile_page(request,players_username):
return render(request, 'portal/portal_partial_profile.html')
I'm not sure why I'm getting this error? I appreciate any feedback and expertise.
Upvotes: 1
Views: 113
Reputation: 174624
Since you are assigning the match to a variable (its a keyword), you need to pass it in, like this:
{% url profile players_username=player.user %}
Another minor correction, your regular expression should be \w+
. The +
means "one or more, but at least one", otherwise your regular expression will not work as you expect (unless all your players have one character usernames).
Upvotes: 3