Django和Bad Request(400) [英] Django and Bad Request (400)
问题描述
添加到我的settings.py:
DEBUG = False
ALLOWED_HOSTS = [
' localhost',
'my_site.com'
]
创建应用程序 test_view
;
添加 hello_world
到 test_view.views
from django.http.response import HttpResponse
def hello_world(request):
return HttpResponse('Hello World !!!')
添加测试路由到urls.py url(r'test /','test_view) views.hello_world')
;
fixed / etc / hosts
127.0.0.1 localhost my_site.com
现在,当我尝试访问 http://my_site.com:8000/test/
django返回错误请求(400)。但是当url是 http:// localhost:8000 / test /
我可以看到我的Hello World页面。可能有什么问题?
UPD:
与 DEBUG = True $ c相同的结果$ c>
UPD2:
还有一个工作主机名是 ubuntu-virtualbox
(电脑的名字)。
但即使我将电脑的名称更改为 my_site
,ubuntu-virtualbox仍然可用,my_site返回不良请求(400)
可能是因为某些系统设置? (它在虚拟机中是干净的ubuntu)。
还是在virtualenv问题?有没有办法跟踪错误?
看起来像django可以看到请求是否不通过dns服务器。 bind /而不是/ etc / hosts中的更改的安装和配置解决了这个问题。
I created new django project; added to my settings.py:
DEBUG = False
ALLOWED_HOSTS= [
'localhost',
'my_site.com'
]
created app test_view
;
added 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'm trying to access http://my_site.com:8000/test/
django returns Bad Request (400). But when url is http://localhost:8000/test/
I can see my Hello World page. What can be wrong?
UPD:
The same result with DEBUG = True
UPD2:
One more working hostname is ubuntu-virtualbox
(computer's name).
But even when I changed computer's name to my_site
, ubuntu-virtualbox was still available and my_site returned Bad Request (400)
May it be because of some system settings? (it's clean ubuntu in virtualbox). Or maybe problem in virtualenv? Is there a way to trace the error?
It looks like django can see if request isn't passed through dns server. Installation and configuration of bind9 instead of changes in /etc/hosts solved this problem.
这篇关于Django和Bad Request(400)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!