Error saving form

0

url.py

     url(r'^paciente/(?P<pk>\d+)/', PatientDetails.as_view(), name='patient_details'),

view.py

def add_deworming(request, pk):
if request.method == 'POST':
    form = DewormingForm(request.POST, patient=Patient.objects.get(pk=pk))
    if form.is_valid():
        deworming = form.save()
        patient=Patient.objects.get(pk=pk)

        return redirect('clinic:patient_detail', patient.pk)
else:
    form = DewormingForm()
return render_to_response('clinic/medicalrecord/register_deworming.html', {'form_deworming': form}, context_instance=RequestContext(request))

I get the following error

  

Reverse for 'patient_detail' with arguments '(3L,)' and keyword arguments '{}' not found. 0 pattern (s) tried: []

this line points to me

            return redirect('clinic:patient_detail', patient.pk)

What can I have wrong?

    
asked by Roly Miranda Díaz 05.05.2017 в 23:09
source

1 answer

1

You are using bad redirect() .

Alternatively, use HttpResponseRedirect along with reverse() as follows:

return HttpResponseRedirect(reverse('patient_details', pk=patient.pk))

See the documentation for HttpResponseRedirect() and < a href="https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse"> reverse() .

    
answered by 10.05.2017 / 21:38
source