Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

400 Bad Request While Using `django.test.client`

I believe I am missing a fundamental setup.

I'm trying to test my API using Django's testing framework.

From the shell, I try:

from django.test import Client
c = Client()
r = c.get('/')

I get a 400 Bad Request, which is not the expected output.

Using a simple curl from the command line:

curl http://localhost

I get the expected output: {"detail":"Authentication credentials...

Am I missing something basic?

like image 647
Anthony C Avatar asked Feb 15 '15 00:02

Anthony C


2 Answers

You can use the test client while DEBUG is False, you just need to add 'testserver' into your ALLOWED_HOSTS setting

like image 82
insertjokehere Avatar answered Oct 17 '22 03:10

insertjokehere


It looks like:

DEBUG = True

is needed in the settings.py file for this to work.

like image 1
Anthony C Avatar answered Oct 17 '22 03:10

Anthony C