0

I tried creating a delete button and basically what it should do is "delete an object when clicked" given its id but my app keeps giving a TemplateSyntaxError at / Could not parse the remainder: '{{doc.id}}' from '{{doc.id}}'. Here's the code for said functionality in my View, Template and Urls.py files respectively

Views.py

def delete_feed(request, pk):
    query = Feed.objects.get(id=pk)
    query.delete()
    return HttpResponse("Deleted!")

Template

<a href="{% url 'delete_feed' pk={{doc.id}} %}"><button type="button"    class="btn btn-danger">Delete Item</button></a>

urls.py

url(r'^delete_feed/(?P<pk>\d+)/$', delete_feed, name='delete_feed'),
mtkguy
  • 277
  • 2
  • 14

2 Answers2

0

Can you try like that

<a href="{% url 'delete_feed' pk=doc.id %}"><button type="button"    class="btn btn-danger">Delete Item</button></a>

we can cann't use within exprssion tag string interploation

if you want know more the document https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#url

Robert
  • 3,373
  • 1
  • 18
  • 34
0

Possible duplicate of this topic. You should double check how you pass the pk argument.

You can try to change

<a href="{% url 'delete_feed' pk={{doc.id}} %}"...

to

<a href="{% url 'delete_feed doc.id' %}"...