javid
javid

Reputation: 419

Django urls.reverse with argument

Stuck on this for a while:

in Django pytest I am trying to do

req = RequestFactory().get(reverse('app_name:app_view_name')) 

But I require the url to have '/[number]' at the end so that UpdateView will recognise the number and display appropriate form from model.

In the browser the links and form submission all work fine, but I am unable to use reverse() in testing. I have tried:

req = RequestFactory().get(reverse('app_name:app_view_name', args=[1])) 

and

req = RequestFactory().get(reverse('app_name:app_view_name'), kwargs=['pk'=1])

but none of these work. I am simply trying to build the url with '/1' added at the end.

Any help much appreciated.

Upvotes: 2

Views: 861

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477180

It expects a dictionary, like you can find in the documentation:

RequestFactory().get(reverse('app_name:app_view_name'),
                     {'pk': 1})

Upvotes: 3

Related Questions