I just deployed my Django site with Heroku and it works at example.herokuapp.com just fine.
The problem I'm having is when I go to example.com, I get Bad Request (400). I've looked at the Django documentation about 400 errors and I can't seem to figure out whats wrong.
I'm using Django 1.9.5 and started the project with cookiecutter-django. Name.com is my domain registrar.
production.py of my settings:
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['example.com'])
I'm not 100% sure how this DJANGO_ALLOWED_HOSTS part of my ALLOWED_HOSTS works, but when I go to my Heroku dashboard and look at my config variables in settings, I see that DJANGO_ALLOWED_HOSTS is .herokuapp.com
Heroku custom domains:
Domain Name DNS Target
*.example.com example.herokuapp.com
example.com example.herokuapp.com
www.example.com example.herokuapp.com
Name.com DNS Records:
Type Host Answer TTL Prio
CNAME www.example.com example.herokuapp.com 300 N/A
CNAME example.com example.herokuapp.com 300 N/A
CNAME *.example.com example.herokuapp.com 300 N/A
In the console I type the host command I get:
$ host www.example.com
www.example.com is an alias for example.herokuapp.com
$ host example.com
example is an alias for example.herokuapp.com
Most answers/forums I can find point at these 3 places to find the error, ALLOWED_HOSTS, Heroku custom domains, and DNS records. But I just can't spot the error.
One suggestion I've found stated to check other areas of the site. I get the same error no matter where I go, such as example.com/about/
Do I need to set something else up at name.com?
Just add .example.com
to ALLOWED_HOSTS
setting using your command line:
heroku config:set DJANGO_ALLOWED_HOSTS=.example.com,example.herokuapp.com
or using the heroku dashboard.
one line solution
#ALLOWED_HOSTS = ['localhost', '127.0.0.1','https://tm-sys-dashbobord.herokuapp.com/', config('SERVER', default='127.0.0.1')]
to replace
ALLOWED_HOSTS =['*']
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