I'm trying to lunch my app on VPS in Debug=False mode. Debug=True works fine but when I change it to false I got this error. I'm using Apache for rendering python pages and Nginx to serve my static files. I tried using this [answer]: Debugging Apache/Django/WSGI Bad Request (400) Error but it's not working at least for me. And this is my wsgi config:
#wsgi.py
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
path = '/var/www/example'
if path not in sys.path:
sys.path.append(path)
And also I've added below code to my settings file:
ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]
example.comwith your real domain name? did you get 404 error for thisALLOWED_HOSTS = '*'also? do you have404.htmltemplate file in your root of template folder?ALLOWED_HOSTS = '*'and the problem solved. Can you explain why my domain not woks? And yes I change example.com to my real domain name.*is not good, fix it by adding your domain(s), looks at ALLOWED_HOSTS*problem?*has security issue, first set*forALLOWED_HOSTSand then in somewhere in view print and see output ofprint(request.META['HTTP_HOST'])orprint(request.get_host()), then set that output (just domain of it as list) to yourALLOWED_HOSTS