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

后端 未结 1 421
我寻月下人不归
我寻月下人不归 2021-02-07 08:59

I\'m currently writing up some basic tests to ensure pages in a medium sized Django application are GETting and POSTing correctly. However, using django.test.client.Client isn\

1条回答
  •  生来不讨喜
    2021-02-07 09:55

    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.

    0 讨论(0)
提交回复
热议问题