Django test client gets 301 redirection when accessing url

后端 未结 2 461
旧时难觅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 11:00

    You have defined a url that matches /query/, but you are testing /query. Django is redirecting to the url with the trailing slash because APPEND_SLASH=True in your settings.

    You probably want to change your test to:

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

提交回复
热议问题