Reputation: 830
I have this in a django view:
edit_url = reverse('ventas:clientes_edit',kwargs={'id':str(self.object.id)})
And this in urls.py:
url(r'^clientes/edit/(?P<pk>\d+)$',forms.ClienteUpdateView.as_view(), name="clientes_edit"),
When I create a new customer via ajax I need to return a reverse url with the id in a JSON data to put in a series of actions buttons for edit, delete... but always I get this error and I don't know how to accomplish it, this the complete error:
NoReverseMatch at /ventas/clientes/add/
Reverse for 'clientes_edit' with arguments '()' and keyword arguments '{'id': '38'}' not found.
Any ideas?
Edit:
The Django version is 1.5
Upvotes: 3
Views: 9838
Reputation: 2535
The kwargs should pass the pk not id to match the url
edit_url = reverse('ventas:clientes_edit',kwargs={'pk':self.object.id})
also your url expects an int pk not string.
Upvotes: 9