Django and Bad Request (400)

I created a new django project; added to my settings.py:

DEBUG = False ALLOWED_HOSTS= [ 'localhost', 'my_site.com' ] 

created test_view application; added by hello_world to test_view.views

 from django.http.response import HttpResponse def hello_world(request): return HttpResponse('Hello World!!!') 

added test route to urls.py url(r'test/', 'test_view.views.hello_world') ; fixed / etc / hosts

 127.0.0.1 localhost my_site.com 

Now when I try to access http://my_site.com:8000/test/ , django returns Bad Request (400). But when url is http://localhost:8000/test/ , I see my Hello World page. What could be wrong?

UPD: Same result with DEBUG = True

UPD2:

Another working host name is ubuntu-virtualbox (computer name). But even when I changed the computer name to my_site , ubuntu-virtualbox was still available, and my_site returned Bad Request (400)

Maybe this is due to some system settings? (it clears ubuntu in virtualbox). Or maybe the problem is in virtualenv? Is there a way to track the error?

+3
django bad-request
Aug 18 '14 at 6:52
source share
4 answers

It looks like django can see if the request is being passed through the DNS server. Installing and configuring bind9 instead of making changes to / etc / hosts solved this problem.

+2
07 Sep '14 at 20:44
source share

This may be a bad cookie. Try to remove them.

+2
Jul 01 '15 at 10:58
source share

You need another line in the hosts file.

 127.0.0.1 localhost 127.0.0.1 my_site.com 

Then in your ALLOWED_HOSTS ...

 ALLOWED_HOSTS = [ 'localhost', '.my_site.com', # not 'my_site.com' ] 

ALSO, and this is probably important when you start your site from a virtual machine, when you start a site using python manage.py runningerver, start it like this ...

python manage.py runserver virtual.server.ip.address:8000

Obviously replace "virtual.server.ip.address" with the actual IP address of the virtual machines.

+1
Aug 19 '14 at 16:43
source share

I type *DEBUG = None* and my django works.

0
May 15, '15 at 11:33
source share



All Articles