Home > Mobile >  Django | Not Found issue while updating record
Django | Not Found issue while updating record

Time:05-18

This is the update form template front end

this is the issue I get when click on form submit button

This is the coding of update template

Other Coding I did

urls.py of web app path adding:

path('update/updaterecord/<int:id>', views.updaterecord, name='updaterecord'),

views.py file of web app : update coding info:

def updaterecord(request, id):
  first = request.POST['first']
  last = request.POST['last']
  member = Members.objects.get(id=id)
  member.firstname = first
  member.lastname = last
  member.save()
  return HttpResponseRedirect(reverse('index'))

CodePudding user response:

Your <form action=""> has a slash at the end, just remove it at it should be good. The url needs to match what is in your urlpatterns[]:

path('update/updaterecord/int:id', views.updaterecord, name='updaterecord'),

The resulting url will be: members/update/updaterecord/8

CodePudding user response:

Your action="" is relative to the current URL since it doesn't have a leading slash.

Since you're on /members/update/8, the action URL segment updaterecord/8 turns that to the absolute URL /members/update/updaterecord/8 you're seeing 404.

If you want your form to target the current page (which is correct in this case), just empty it or get rid of it:

<form method="post">

is sufficient in this case.

Beyond that, please look into Django's form modules and generic views; you're currently doing a lot of manual work you don't need to.

  • Related