gpt4 book ai didi

python - django.core.urlresolver.reverse - NoReverseMatch : Reverse for '...' with arguments '()' and keyword arguments '{}' not found

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:32 25 4
gpt4 key购买 nike

我在 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.

我其他时候也遇到过这个问题,同样是在管理员中,在 get_urls() 方法中定义了 url。我试图在互联网上搜索任何合适的解决方案,但没有一个对我有用。有帮助吗?

谢谢

最佳答案

尝试:
1. 将 $ 添加到 url,如 r'^/mailsent/$'
2. 使用 from django.conf.urls import patterns, include, url 而不是
否则:D:\Program Files (x86)\python273\lib\site-packages\django\conf\urls\defaults.py:3: DeprecationWarning: django.conf.urls.defaults 已弃用;使用 django.conf.urls 代替
弃用警告)
3. from django.core.urlresolvers import reverse 注意 urlresolvers 末尾的 's'
4.可以用reverse_lazy相反

关于python - django.core.urlresolver.reverse - NoReverseMatch : Reverse for '...' with arguments '()' and keyword arguments '{}' not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20397999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com