gpt4 book ai didi

Django 和错误请求 (400)

转载 作者:行者123 更新时间:2023-12-02 09:01:01 31 4
gpt4 key购买 nike

我创建了新的 django 项目;添加到我的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');修复了/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

的结果相同

UPD2:

另一个工作主机名是ubuntu-virtualbox(计算机名称)。但即使我将计算机名称更改为 my_site,ubuntu-virtualbox 仍然可用,并且 my_site 返回 Bad Request (400)

可能是因为某些系统设置的原因? (它是 virtualbox 中干净的 ubuntu)。或者 virtualenv 可能有问题?有办法追踪错误吗?

最佳答案

这可能是一个坏 Cookie。尝试删除它们。

关于Django 和错误请求 (400),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357744/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com