我在视图中传递一个字符串参数,但它无效。
url(r'^users/(?P<user_type>\w+)/$', views.users, name='users'),
url(r'^users/$', views.users, name='users')
视图是: -
def users(request, user_type=None):
链接是: -
<a href="{% url 'users' %}">All Users</a>
<a href="{% url 'users' customers %}">Customers</a>
<a href="{% url 'users' promoters %}">Promoters</a>
但是当我访问没有参数的视图时它给出错误
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+)/$']
答案 0 :(得分:1)
使用此选项并检查
url(r'^users/(?P<user_type>\w+)/$', views.users, name='users_type'),
url(r'^users/$', views.users, name='users')
链接是:
<a href="{% url 'users' %}">All Users</a>
<a href="{% url 'users_type' "customers" %}">Customers</a>
<a href="{% url 'users_type' "promoters" %}">Promoters</a>