conjenks conjenks - 1 year ago 47
Python Question

Django: Reverse for 'delete' with arguments '(49,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['tidbit/delete_tidbit/']

Can't figure out how to solve this error

Here is the snippet:

urlpatterns = [
url(r'^delete_tidbit/', views.delete_tidbit, name='delete'),

The view:

def delete_tidbit(request, pk):
tidbit = Tidbit.objects.get(pk=pk)
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

And the portion of the template that raises this error:

<a href="{% url 'delete' %}">

Answer Source

The issue is here:

url(r'^delete_tidbit/', views.delete_tidbit, name='delete'),

This URL doesn't accept an argument, where as you are trying to give it one.

Try this instead:

url(r'^delete_tidbit/(?P<pk>.*)', views.delete_tidbit, name='delete'),

But beware: you are accepting GET requests to delete items in your database, any crawler coming across those links may try to follow them and inadvertently delete your data. Consider using a GET that delivers a form to be POSTed to ensure an actual user is doing the action.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download