Django允许带有端口号的主机

编程入门 行业动态 更新时间:2024-10-25 16:26:26
本文介绍了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允许带有端口号的主机

本文发布于:2023-08-07 14:20:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口号   主机   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!