简体   繁体   English

传递的字符串参数在django1.9中不起作用

[英]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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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