Django test client gets 301 redirection when accessing url

后端 未结 2 493
旧时难觅i
旧时难觅i 2021-01-17 10:17

I am writing unittests for django views. I have observed that one of my views returns redirection code 301, which is not expected.
Here is my views.py mentioned earlier.

2条回答
  •  半阙折子戏
    2021-01-17 10:57

    For me, the problem was that I mistakenly ran the tests with a setting.py file that had SECURE_SSL_REDIRECT = True. Changing to SECURE_SSL_REDIRECT = False solved the issue.

    Another option is to use the client with secure=True, i.e.:

    response = self.client.post('/query/', {}, secure=True)
    

    which will make the client emulate an HTTPS request.

提交回复
热议问题