Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad Request (400) using Django, Heroku, and Name.com

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?

like image 794
Brian Head Avatar asked Apr 09 '16 18:04

Brian Head


2 Answers

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.

like image 142
matagus Avatar answered Nov 03 '22 18:11

matagus


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 =['*'] 
like image 1
Mr Coder Avatar answered Nov 03 '22 16:11

Mr Coder