【发布时间】:2014-12-18 05:27:02
【问题描述】:
我有一个urls.py 文件,其中包含多个具有相同命名参数和正则表达式但名称不同的网址。当我使用 {% url 'name' param %} 从模板调用视图函数时,它会调用 urls.py 文件中第一个出现的函数,而不管名称。这里是urls.py的内容:
urlpatterns = patterns('accountsearch.views',
url(r'^$', 'account_search', name='account_search'),
url(r'(?P<account_uuid>[a-zA-Z0-9\-]+)/(?P<user_uuid>[a-zA-Z0-9\-]+)/$','reset_password',name='reset_password'),
url(r'(?P<account_uuid>[a-zA-Z0-9\-]+)/(?P<user_uuid>[a-zA-Z0-9\-]+)/$','reset_securityquestions',name='reset_securityquestions'),
我正在尝试使用以下模板从模板中调用reset_securityquestions:
"{% url 'reset_securityquestions' account.uuid user.uuid %}">
但它改为调用reset_password。
如果我将urls.py 中的网址顺序更改为:
urlpatterns = patterns('accountsearch.views',
url(r'^$', 'account_search', name='account_search'),
url(r'(?P<account_uuid>[a-zA-Z0-9\-]+)/(?P<user_uuid>[a-zA-Z0-9\-]+)/$', 'reset_securityquestions',
name='reset_securityquestions'),
url(r'(?P<account_uuid>[a-zA-Z0-9\-]+)/(?P<user_uuid>[a-zA-Z0-9\-]+)/$', 'reset_password', name='reset_password'),
并使用以下方式致电reset_password:
{% url 'reset_password' account.uuid user.uuid %}
它调用reset_security_questions 函数。我哪里错了?
【问题讨论】: