I have a problem with url resolution in a view:
我有一个关于url解析的问题:
# URLS.PY
from django.conf.urls.defaults import url, include, patterns
from acomea.contact.cms.views import (
ConfirmPrivacyFormView, CancelContactTemplateView, ConfirmPrivacyDataTemplateView, CancelMailSentTemplateView
)
urlpatterns = patterns('',
url(
r'^',
ConfirmPrivacyFormView.as_view(),
name="contact_contact_confirm_privacy_form"
),
url(
r'^/data-confirmed/$',
ConfirmPrivacyDataTemplateView.as_view(),
name="contact_contact_confirm_privacy_accept_data"
),
url(
r'^/mailsent/',
CancelMailSentTemplateView.as_view(),
name="contact_contact_confirm_privacy_delete_mailsent"
),
url(
r'^/remove-contact/',
CancelContactTemplateView.as_view(),
name="contact_contact_confirm_privacy_delete_contact"
),
)
# resolve
>>>from django.core.urlresolver import reverse
>>>reverse("contact_contact_confirm_privacy_accept_data")
NoReverseMatch: Reverse for 'contact_contact_confirm_privacy_accept_data' with arguments '()' and keyword arguments '{}' not found.
I experienced this problem other times, also in the admin with urls defined in get_urls()
method. I've tried to search on the internet any suitable solution but none of them did't worked for me. Any help?
我以前也遇到过这个问题,同样在管理中,在get_urls()方法中定义了url。我试图在网上搜索任何合适的解决方案,但没有一个对我不起作用。任何帮助吗?
Thanks L.
由于L。
1 个解决方案
#1
1
Try:
1. add $ to url like r'^/mailsent/$'
2. use from django.conf.urls import patterns, include, url
instead
Otherwise: D:\Program Files (x86)\python273\lib\site-packages\django\conf\urls\defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
DeprecationWarning)
3. from django.core.urlresolvers import reverse
notice the 's' at the end of urlresolvers
4. You can use reverse_lazy instead
试:1。添加$ url像r ^ / mailsent / $ 2。从django.conf使用。url导入模式,包括,url相反:D:\程序文件(x86)\python273\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \urls\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。py:3: DeprecationWarning: django.conf.urls.default;使用django.conf。url而不是DeprecationWarning)3。从django.core。在urlresolvers 4结束时,urlresolvers导入反向注意到“s”。您可以使用reverse_lazy
#1
1
Try:
1. add $ to url like r'^/mailsent/$'
2. use from django.conf.urls import patterns, include, url
instead
Otherwise: D:\Program Files (x86)\python273\lib\site-packages\django\conf\urls\defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
DeprecationWarning)
3. from django.core.urlresolvers import reverse
notice the 's' at the end of urlresolvers
4. You can use reverse_lazy instead
试:1。添加$ url像r ^ / mailsent / $ 2。从django.conf使用。url导入模式,包括,url相反:D:\程序文件(x86)\python273\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \urls\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。py:3: DeprecationWarning: django.conf.urls.default;使用django.conf。url而不是DeprecationWarning)3。从django.core。在urlresolvers 4结束时,urlresolvers导入反向注意到“s”。您可以使用reverse_lazy