I am making progress in the development of django with an application, initially with the use of function-based views, my idea is also to handle views based on classes, and I am with an application that allows me to recover a record from a table to From the ID of that table, the view is:
def recibo_edit(request, id_recibo):
recibo = Recibo.objects.get(id=id_recibo)
if request.method == 'GET':
form = ReciboForm(instance=recibo)
else:
form = ReciboForm(request.POST, instance=recibo)
if form.is_valid():
form.save()
return redirect('recibo:recibo_listar')
return render(request, 'recibos/recibo_form.html', {'form': form})
While in the urls.py file of the application I receive, I have the following:
app_name ='recibos'
urlpatterns = {
path('', index, name='index'),
path('nuevo/', recibo_view, name='recibo_nuevo'),
path('listar/', recibo_list, name='recibo_listar'),
path('editar/(?P<id_recibo>\d+)/$', recibo_edit, name='recibo_editar'),
}
When I run the django server, and use the path to retrieve a record: the id = 365 that exists in the database, it returns the following error:
The current path, recibos/editar/365/, didn't match any of these
Apparently everything is fine, but I can not identify where the error is. Thank you in advance for your comments.
Thank you very much! Gustavo.