I have created a view that accepts 3 arguments but I get the following error in the homepage.Reverse for 'evolucion_paciente' with arguments '(5,)' not found. 1 pattern(s) tried: ['evolucion_paciente/(?P[0-9]+)/(?P[0-9]+)$']
Project/views.py -- One of my views
def VerEvoluciones(request, id):
if request.method == 'GET':
paciente = Paciente.objects.get(id= id)
evoluciones = Evolucion.objects.filter(paciente= id).order_by('-fechaEvolucion')
evolucionForm = EvolucionForm()
else:
return redirect('index')
return render(request, 'evoluciones.html', {'evolucionForm': evolucionForm, "Evoluciones": evoluciones, "Paciente": paciente})
Another View, and the one which im having troubles with
def VerEvolucion(request, id, id_e):
evolucionForm= None
evolucion= None
try:
if request.method == 'GET':
paciente = Paciente.objects.get(id= id)
evolucion = Evolucion.objects.filter(paciente= id).get(id= id_e)
evolucionForm = EvolucionForm(instance= evolucion)
else:
return redirect('index')
except ObjectDoesNotExist as e:
error = e
return render(request, 'evolucion.html', {'evolucionForm': evolucionForm,
'Evolucion': evolucion,
'Paciente': paciente,
'Ver': True})
In my template, the link that i need to redirect me from my firt view to my second one
<a href="{% url 'evolucion_paciente' evolucion.id %}" class="btn btn-warning">Ver</a>
As the errors says, you defined a url pattern like:
evolucion_paciente/(?P<id>[0-9]+)/(?P<id_e>[0-9]+)$
so you need to pass two parameters, one for id
and one for id_e
. But in your {% url … %}
, you only passed one:
{% url 'evolucion_paciente' evolucion.id %}
You need to pass an extra one:
<a href="{% url 'evolucion_paciente' value-for-id evolucion.id %}" class="btn btn-warning">Ver</a>
where you need to fill in value-for-id
with the value for id
. Probably something like:
<a href="{% url 'evolucion_paciente' evolucion.paciente.id evolucion.id %}" class="btn btn-warning">Ver</a>