Why do I get this error with reverze_lazy?

1

I have the following code of my function to create a form

 def correspondencia_view(request):

 if request.method == 'POST':
        form = CorrespondenciaForm(request.POST)
        if form.is_valid(): 
         # si es todo correcto el archivo es guardado
                 form.save()
                 #este es el retorno de la vista url que esta en el archivo urls.py        
                 return redirect('correspondencia:corresp_listar')           
                 # caso contrario se vuelve otra vez a generar el formulario
else:
     form = CorrespondenciaForm() 
return render(request, 'registrarCorrespondencia/index.html', {'form': form})

and my class

  class CorrespCrear(CreateView):

   model = corresp
   form_class = CorrespondenciaForm
   template_name = 'registrarCorrespondencia/index.html'
   success_url = reverse_lazy('correspondencia:corresp_listar')

and my urls.py is like this

 url(r'^nuevo/$', CorrespCrear.as_view(), name='registrar_corresp'),

BUT I get an error that is as follows:

NoReverseMatch at / correspondence / new /

Reverse for 'corresp_listar' not found. 'corresp_listar' is not a valid view function or pattern name.

This error I get when I put in save in my form, but instead of rediccionarme to the page where is my data table, I get that, because it could be?

    
asked by Lun 11.05.2018 в 17:06
source

1 answer

0

Well the problem itself was in the URL and the reverse_lazy

I just changed what was corresponded to what is my list that I have created, thanks to (German Alzate) that if he was right with his comment put there.

my url would be haci     url (r '^ new / $', CorrespCreate.as_view (), name = 'new'),

url(r'^listar/$', CorrespList.as_view(), name='corresp_list'),

where my reverse_lazy changes it so

 class CorrespCrear(CreateView):
 model = corresp
 form_class = CorrespondenciaForm
 template_name = 'registrarCorrespondencia/index.html'
 success_url = reverse_lazy('correspondencia:corresp_list')

and in my function correspon_view_view

 return redirect('correspondencia:corresp_list')    

and everything is fine with me:)

    
answered by 11.05.2018 в 18:05