12

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?

2
  • What exactly is you question/problem here? Commented Feb 15, 2015 at 21:06
  • test.Client was returning an unexpected value, 400 Bad Request. It should have been returning json from my API. I wasn't sure what I had wrong in my setup. It looks like I just had the DEBUG flag set incorrectly (see my answer below). Commented Feb 15, 2015 at 21:32

2 Answers 2

19

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

Sign up to request clarification or add additional context in comments.

1 Comment

I kept getting the error in question even with DEBUG=True for some reason. Adding 'testserver' fixed it. If somebody could explain why is that so, I'd be grateful (tests were running fine with manage.py test, the problem persisted only in shell)
1

It looks like:

DEBUG = True 

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

1 Comment

I'll leave this answer unaccepted for a couple of days in case something better comes along.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.