gpt4 book ai didi

django 与命名空间反向

转载 作者:行者123 更新时间:2023-12-02 09:56:53 27 4
gpt4 key购买 nike

我收到此错误:

The included urlconf 'unsitiodigital.urls' does not appear to have any patterns in it.

回溯指向这一行

class Contacto(FormView):
template_name = "contacto.html"
form_class = FormContacto
success_url = reverse("main:mensaje_enviado") -->This Line

def form_valid(self, form):

form.send_email()
return super(Contacto, self).form_valid(form)

有有效的模式,无需 reverse 行即可工作。urls.py - 一般

urlpatterns = [    
url(r'^', include('main.urls', namespace="main")),
url(r'^admin/', include(admin.site.urls)),
]

urls.py - 主要

from django.conf.urls import url

from main import views

urlpatterns = [
url(r'^$', views.Inicio.as_view(), name='inicio'),
url(r'^quienes_somos/$', views.QuienesSomos.as_view(), name='quienes_somos'),
url(r'^opciones/$', views.Opciones.as_view(), name='opciones'),
url(r'^contacto/$', views.Contacto.as_view(), name='contacto'),
-> url(r'^mensaje_enviado/$', views.MensajeEnviado.as_view(), name='mensaje_enviado')
]

那么,“哪一个是反向的正确用户?”。非常感谢。

最佳答案

包含路径一定是错误的

url(r'^', include('main.urls', namespace="main")),  # the 'main.urls' path must be wrong

有一些方法可以包含其他网址。尝试从 main.url 模块导入模式

from main.urls import urlpatterns as main_urls

url(r'^', include(main_urls, namespace="main"),

您还必须使用 reverse_lazy在 success_url 中。

from django.core.urlresolvers import reverse_lazy

class Contacto(FormView):
template_name = "contacto.html"
form_class = FormContacto
success_url = reverse_lazy("main:mensaje_enviado")

It is useful for when you need to use a URL reversal before your project’s URLConf is loaded.

关于django 与命名空间反向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30539663/

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