Django允许带有端口号的主机 [英] Django allowed hosts with port number

查看:104
本文介绍了Django允许带有端口号的主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django作为后端,它在回送接口的8000端口上运行。因此,当我尝试使用DEBUG = False进行启动时,前端发出的任何请求都出现500错误。
我将ALLOWED_HOSTS设置为:

I use django as a backend and it's running on 8000 port at the loopback interface. So, when I'am to try start it with DEBUG = False, I got 500 error on any request from a frontend. I set my ALLOWED_HOSTS as:

 ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '127.0.0.1:8000', 'localhost:8000', '*',]

但这不是为我工作。
是否可以禁用此选项或该怎么做?

But this doesn't work for me. Is it possible disable this option or how I can do that?

更新
所以我刚刚声明了变量ALLOWED_HOSTS高于默认值ALLOWED_HOSTS = []。抱歉,您的疏忽。

UPDATE So I just declared variable ALLOWED_HOSTS above of default ALLOWED_HOSTS = []. Sorry for the inattention.

推荐答案

通常,不当的django ALLOWED_HOSTS应该导致错误请求(400) 。

Normally, improper django ALLOWED_HOSTS should lead to "Bad Request (400)".

更多信息, DisallowedHost (子类为 SuspitiousOperation )由 HttpRequest.get_host()中的请求引发,稍后由请求hadler ,返回 400 HTTP响应。如果在 resolver.resolve400()中发生异常,则可能会出现 500 错误。

In more details, DisallowedHost (child class to SuspitiousOperation) is raised by request in HttpRequest.get_host(), and is processed later by request hadler, returning 400 HTTP response. You might get 500 error if an exception is occured in resolver.resolve400().

@Denis可能是您被ALLOWED_HOSTS破坏了。我建议您调试它的值(例如记录它)。查看验证工作,您的 *应该跳过任何主机验证

@Denis may be you mangled ALLOWED_HOSTS. I'd suggest you debug its value (logging it for example). See how validation works, your '*' should skip any host validation

这篇关于Django允许带有端口号的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆