我收到了这个错误:
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 - general
urlpatterns = [
url(r'^', include('main.urls', namespace="main")),
url(r'^admin/', include(admin.site.urls)),
]
urls.py - main
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')
]
那么,¿哪个是反向的正确用户?非常感谢。
答案 0 :(得分:7)
包含路径必须是错误的
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"),
您还必须在success_url中使用reverse_lazy。
from django.core.urlresolvers import reverse_lazy
class Contacto(FormView):
template_name = "contacto.html"
form_class = FormContacto
success_url = reverse_lazy("main:mensaje_enviado")
在项目的URLConf加载之前需要使用URL反转时,它非常有用。