1

I get Bad Request (400) on my localhost when my DEBUG = False. Even I configured ALLOWED_HOSTS. I have been searching all over stackoverflow but still can't find the source of the problems.

DEBUG = False

ALLOWED_HOSTS = ['localhost','127.0.0.1']
sdg
  • 701
  • 1
  • 5
  • 12
  • It should work with just `localhost`. What version of Django are you using? – Jessie Mar 13 '17 at 21:39
  • I am using Django==1.10.5 – sdg Mar 13 '17 at 22:42
  • 1
    I'm thinking the 400 is coming from something else and isn't related to the `ALLOWED_HOSTS`, because your config is right. Look at [this](http://stackoverflow.com/questions/19875789/django-gives-bad-request-400-when-debug-false), maybe it helps – Jessie Mar 13 '17 at 22:59
  • 1
    That's what I thought too but it is clear that the bad request only appears when the DEBUG = False. I checked on that link but they don't answer my issue. – sdg Mar 14 '17 at 01:17
  • 1
    Try making a new, fresh project and just change those two configs and see if it works. That rules out any issues from your python or django installs. If that doesn't work, see if any middlewares you've installed are causing the problem. Commenting out things in your config is a surprisingly effective way to narrowing down a problem like this. – Jessie Mar 14 '17 at 01:20
  • As an option, try writing your own 400 handler and get the actual error manually: https://docs.djangoproject.com/en/1.10/ref/urls/#handler400 – Andrey Shipilov Mar 14 '17 at 02:07
  • I started a new project and the result is the same except when I put 127.0.0.1, together with localhost, in the ALLOWED_HOSTS: then I got: Not Found The requested URL / was not found on this server. I am thinking this error is caused by an middleware just like you suggested user2896976. Now I just need to figure an effective way to isolate that middleware. – sdg Mar 14 '17 at 17:39

1 Answers1

0

Try adding '*' to the list just in case and see if that helps.

NS0
  • 6,016
  • 1
  • 15
  • 14