[Django]-How to pass extra keyword arguments when using Django RequestFactory?

6👍

You can pass keyword arguments to the user_pos method the normal way:

response = views.user_kw(request, uid=1, uname='foo')

Your error message shows that you tried:

response = views.user_kw(request, {"uid": 1, "uname": "foobar"})

This isn’t passing keyword arguments, it’s passing a dictionary as a positional argument. Note that you can use ** to unpack the dictionary:

response = views.user_kw(request, **{"uid": 1, "uname": "foobar"})

Leave a comment