URL 标记拒绝查找视图,即使它存在于 views.py 和 urls.py



标题几乎概括了它——我在模板中有这个标签:

<a href="{% url mainapp.views.send_registration_email_view user_email=for_user.email,company_number=company.pk,organisation='org' %}">

在urls.py:

(r'^send/registrationlink/(?P<user_email>[^/]+)/(?P<company_number>[^/]+)/(?P<organisation>w+)/?$', 'mainapp.views.send_registration_email_view'),

在mainapp/views.py:中

def send_registration_email_view(request, user_email = None, company_number = None, organisation = None):

然而,试图查看导入模板的页面,在该模板中找到有问题的行,会导致以下错误:

TemplateSyntaxError: Caught NoReverseMatch while rendering: Reverse for 'mainapp.views.send_registration_email_view' with arguments '()' and keyword arguments '{'organisation': u'org', 'company_number': u'UN58e2391e-51a5-11e1-bb6a-e89a8f7f9c14', 'user_email': ''}' not found.

我在同一个模板中也有这些标签,它们工作得很好:

<a href="{% url mainapp.views.registration_view for_user=for_user %}">
<a href="{% url mainapp.views.consent_view for_user=for_user %}">

那么-有人知道为什么django不喜欢我所做的吗

正则表达式的这一部分:(?P<user_email>[^/]+)需要至少一个字符,但您传递的是一个空字符串作为user_email。在正则表达式中,+的意思是"一个或多个"。将其更改为*也可以接受空字符串。

http://docs.python.org/library/re.html#regular-表达式语法

最新更新