Django Environment Identifying the DEBUG as False while it is set to True
I get and error
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
Below are the edits I attempted seeing at stackoverflow's suggestion from various (queries)[https://stackoverflow.com/questions/66923320/why-it-doesnt-set-debug-true] around 5 of them were relevant and tried to edit accordingly.
... I also checked for views and urls for any filename mistyping and typo errors. Yet I am getting
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
I closed the session and changed the open .py file default from vscode and then with python. Yet this error is persistent PLEASE HELP
My settings.py has DEBUG = TRUE
ALLOWED_HOSTS = []
I have also tried ALLOWED_HOSTS = ['*']
then ALLOWED_HOSTS = ['localhost']
then ALLOWED_HOSTS = ['127.0.0.1']
then ALLOWED_HOSTS = ['localhost', '127.0.0.1']
once with DEBUG = FALSE
and then with DEBUG = TRUE
Alternately I Tried this
TEMPLATE_DEBUG = DEBUG
if not DEBUG:
ALLOWED_HOST = ['0.0.0.0', '127.0.0.1','localhost','*']
ALLOWED_HOSTS = []```
The issue still persists despite Changing VS code settings .py extension change from VSCODE to Python interpreter and vice versa.
First and foremost, your variable is wrong.
if not DEBUG:
ALLOWED_HOST = ['0.0.0.0', '127.0.0.1','localhost','*']
this should be ALLOWED_HOSTS (with an S)
the allowed_hosts should be something like this:
ALLOWED_HOSTS = ['localhost','127.0.0.1',]
regardless if you're in debug or not, this MUST be set. I'd further recommend something like this to ensure you get a value for allowed_hosts:
if not DEBUG:
ALLOWED_HOSTS = ['<prod DNS, host, and/or IP>',]
else:
ALLOWED_HOSTS = ['localhost','127.0.0.1',]