Django allowed hosts with a port number

I use django as a backend, and it works on 8000 ports in the loopback interface. Therefore, when I try to start it using DEBUG = False, I received 500 errors on any request from the external interface. I set my ALLOWED_HOSTS as:

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

But this does not work for me. Is it possible to disable this option or how can I do this?

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

+6
source share
1 answer

Usually the wrong django ALLOWED_HOSTS should lead to "Bad Request (400)" .

In more detail, DisallowedHost (a child class before SuspitiousOperation ) is created on request in HttpRequest.get_host() and processed later by the request hadler , returning a 400 HTTP response. You may get a 500 error if an exception occurred in resolver.resolve400() .

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

+7
source

Source: https://habr.com/ru/post/957568/


All Articles