Home > front end >  Why is the html not recognising the view function?
Why is the html not recognising the view function?

Time:01-15

I am trying to build an inventory management with Django. When building delete option, I am encountering an error. The error message is "Reverse for 'delete' not found. 'delete' is not a valid view function or pattern name."

I will paste my code below.

Delete function code:

def delete(request, iid):
  obj = inventory.objects.get(id=iid)
  obj.delete()
  return render(request, 'main/lists.html')

HTML Template code:

 <a  href="{% url 'delete' i.id %}" role="button">Delete</a>

Urls.py code:

urlpatterns = [
path('', views.index, name="index"),
path('lists', views.lists, name="lists"),
path('add', views.add, name="add"),
path('edit', views.edit, name="edit"),
path('delete/<int:id>', views.delete, name="delet") ]

Please give me a valid solution.

CodePudding user response:

In urls.py the url pointing to the method is called delet. Update it to delete on urls.py or to delet on the HTML template.

CodePudding user response:

From the docs you can do this:

{% url 'delet' i.id as the_url %}

<a  href="{{ the_url }}" role="button">Delete</a>
  •  Tags:  
  • Related