Django Test Client post() returns 302 despite error on view's post() Django Test Client post() returns 302 despite error on view's post() django django

Django Test Client post() returns 302 despite error on view's post()


It's not totally clear why you're getting a redirect, but if you want to follow it you need to tell RequestClient to follow redirects - per the documentation:

If you set follow to True the client will follow any redirects and aredirect_chain attribute will be set in the response object containingtuples of the intermediate urls and status codes.

So your test code should look like:

response = client.post("/app/mymodel/create/", follow=True)

It'd be worth checking the request chain to see where exactly it was routed.