Django urls.reverse with argument

863 views Asked by At

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.

1

There are 1 answers

0
willeM_ Van Onsem On BEST ANSWER

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

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