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?
UPDATE So I just declared variable ALLOWED_HOSTS above of default ALLOWED_HOSTS = []. Sorry for the inattention.
I guess it can help you. when you run python manage.py runserver, it will take 127.0.0.1 as default ip address and 8000 as default port number which can be configured in your python environment. In your python setting, go to <your python env>\Lib\site-packages\django\core\management\commandsunserver.pyand set 1. default_port = '<your_port>'
It simply mentions the list of address from where your site can be accessed. like ALLOWED_HOSTS = ['your_site.com', 'IP_ADDRESS_OF_YOUR_SITE'] for more information visit docs And for why ['*'] being dangerous and why ALLOWED_HOST was added to django please refer to this post.
Save the file as a management command of your own, e.g. under <app-name>/management/commands/runserver.py: from django.conf import settings from django.core.management.commands import runserver class Command(runserver.Command): default_port = settings.RUNSERVER_PORT
A dictionary containing the settings for all caches to be used with Django. It is a nested dictionary whose contents maps cache aliases to a dictionary containing the options for an individual cache. The CACHES setting must configure a default cache; any number of additional caches may also be specified.
Normally, improper django ALLOWED_HOSTS should lead to ”Bad Request (400)”
.
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 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With