0

i was trying to delete a record in model, can't query the object by id

my code

Html :

<a href="{% url 'todo:delete' todo.id %}">DELETE</a>

url.py :

url(r"^del/$" ,views.DeleteContent,name="delete"),

views.py :

def DeleteContent(request,u_id):
    if not request.user.is_authenticated():
        return redirect('accounts:login')
    #todo=ToDo.objects.all()
    todo=ToDo.object.filter(u_id=id)
    todo.delete()
    return render(request,"index.html")
Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
naveenv
  • 59
  • 1
  • 1
  • 5
  • Possible duplicate of [What is a NoReverseMatch error, and how do I fix it?](https://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – Sayse Aug 23 '17 at 06:21

1 Answers1

2

change your url structure to this

url(r"^del/(?P<u_id>\d+)/$" ,views.DeleteContent,name="delete"),
Exprator
  • 26,992
  • 6
  • 47
  • 59