I need a regex that should match the following strings:
- users/24
- users/24/
- users/24/sam
- users/24/sam/
- users/24/sam/tab_name
- users/24/sam/tab_name/
where, pk=24, username=sam, tab=tab_name
So far I have a url as:
url(r'^users/(?P<pk>\d+)/(?P<username>[-\w\d]+)?/?(?P<tab>[-\w\d]+)?/?', vw.ProfileView.as_view(), name='profile')
The above url matches everything above. But while using
{% url 'profile' pk=24 username="sam" tab="tab_name" %}
the output is : users/samtab_name
I know the problem here i.e, /?
optional slash. But I don't want it to be optional when using {% url 'profile' pk=24 username="sam" tab="tab_name" %}
Help me with this.