Home > Net >  Page not found (404) at /remove/, Hy i am a beginner and i want to delete data then i get this error
Page not found (404) at /remove/, Hy i am a beginner and i want to delete data then i get this error

Time:09-20

 urls.py 

'''

    urlpatterns = [
    path('', views.index, name='index' ),
    path('form', views.form, name='form' ),
    path('about', views.about, name='about' ),
    path('add_data', views.add_data, name='add_data' ),
    path('remove', views.remove, name='remove' ),
    path('remove/<int:emp_id>', views.remove, name='remove' ),
] 

'''

 views.py 

'''

def remove(request,emp_id = 0):
    if emp_id:
        try:
            emp_removed=Members.objects.get(id=emp_id)
            emp_removed.delete()
            return HttpResponse('remover data successfully..')
        except:
            pass
    emps=Members.objects.all()
    context={
        'emp':emps
    }
    return render(request,'remove.html', context)

'''

 remove.html

'''

<ul >
       {% for i in emp %}
      <li><a  href="/remove/{{emp.id}}">{{i.firstname}}</a></li>
      {% endfor %}
  </ul><ul >
       {% for i in emp %}
      <li><a  href="/remove/{{emp.id}}">{{i.firstname}}</a></li>
      {% endfor %}
  </ul>

i want to delete some item from my template and i am getting the above mentioned error, if anyone know the answer please tell me ... This page shows when i run this code

CodePudding user response:

that problem is probably related to the directory your template is in. Verify the TEMPLATES DIRS on settings.py file and verify if the template you have (.html file) is in the same directory. Check this for more information about the topic.

CodePudding user response:

You need to add forward slash / at the end of all the routes, so:

urlpatterns = [
    path('', views.index, name='index' ),
    path('form/', views.form, name='form' ),
    path('about/', views.about, name='about' ),
    path('add_data/', views.add_data, name='add_data' ),
    path('remove/', views.remove, name='remove' ),
    path('remove/<int:emp_id>/', views.remove, name='remove' ),
]

Then enter requested url as http://127.0.0.1:8000/remove/.

  • Related