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

谁说胖子不能爱 提交于 2019-12-03 05:39:37
Hamish

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 a redirect_chain attribute will be set in the response object containing tuples of the intermediate urls and status codes.

So your test code should look like:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!