简体   繁体   中英

string parameter passing not working in django1.9

I am passing a string parameter in view but its not working.

url(r'^users/(?P<user_type>\w+)/$', views.users, name='users'),
url(r'^users/$', views.users, name='users')

view is:-

def users(request, user_type=None):

Link is:-

<a href="{% url 'users' %}">All Users</a>
<a href="{% url 'users' customers %}">Customers</a>
<a href="{% url 'users' promoters %}">Promoters</a>

But its giving error when i access view without parameter

Reverse for 'users' with arguments '('',)' and keyword arguments '{}' not found. 2 pattern(s) tried: ['administrator/users/$', 'administrator/users/(?P<user_type>\\w+)/$']

Exception Value: Reverse for 'users' with arguments '('',)' and keyword arguments '{}' not found. 2 pattern(s) tried: ['administrator/users/$', 'administrator/users/(?P<user_type>\\w+)/$']

Use this and check

url(r'^users/(?P<user_type>\w+)/$', views.users, name='users_type'),
url(r'^users/$', views.users, name='users')

Link is:

 <a href="{% url 'users' %}">All Users</a> <a href="{% url 'users_type' "customers" %}">Customers</a> <a href="{% url 'users_type' "promoters" %}">Promoters</a> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM