django test client always returning 301 django test client always returning 301 django django

django test client always returning 301


Standardly I've figured out the answer while writing the question... hopefully this will be useful to somebody else!

Somehow the SSL config snuck into my dev settings. In particular I've had the following

SSL_FORCE_HOST = 'example.com'

enabled, which seems to be a problem - after disabling it in dev, the problem disappeared.


There is also a secure flag that you can set to solve the issue with redirection to https. In my case I tested post:

response = self.client.post(url, data, secure=True)

but client.get() also has this flag.


Check that it is running the test with debug enabled in settings.py. Running with debug disabled can causes it to redirect.

DEBUG = True

I encountered this in a code base that was modified to disable debug by default.