...">

How to backlink url with primary key in django

I have the following URL entry for my application:

url(r'^(?P<pk>\d+)/(?P<action>add|edit)/type/$', 'customer.views.edit', name='customer-edit'), 

I want to publish this url using reverse. When I do the following, I get a NoReverseMatch error message:

 self.client.post(reverse('customer-edit'), {'something:'something'}, follow=True) 

This is a complete error: NoReverseMatch: Reverse for 'customer-edit' with arguments '()' and keyword arguments '{}' not found.

Do i need to pass arguments or kwargs to the opposite? If so, how do they look to match the above URL?

+4
source share
1 answer

To pass args to a URL, you can pass a variable named args type tuple to reverse :

 self.client.post(reverse('customer-edit', args=(1, 'add',)), {'something:'something'}, follow=True) 

another problem is that dict has Syntax Error

 self.client.post(reverse('customer-edit', args=(1, 'add',)), {'something' : 'something'}, follow=True) 

Hope this helps you!

+4
source

Source: https://habr.com/ru/post/1491759/


All Articles