I get an Error 400: Bad Request on custom Heroku domain, but works fine on foo.herokuapp.com
Asked Answered
K

3

29

I've just pushed a Django project up to Heroku. It works fine at http://rtd-staging.herokuapp.com/rtd2015/, but for some reason I get a 400 error: Bad Request when I visit it using: http://staging.researchthroughdesign.org/rtd2015/

I know that the CNAME was setup correctly because during the process of pushing up to heroku it said that the Heroku app had crashed, so it was definitely pointing to the correct app.

Here is the log for the error:

2014-04-23T18:32:29.981976+00:00 heroku[router]: at=info method=GET path=/ host=staging.researchthroughdesign.org request_id=b8fe3ac9-e062-493b-b3bf-862c60e4001b fwd="82.34.146.252" dyno=web.1 connect=1ms service=7ms status=400 bytes=226
Kortneykoruna answered 23/4, 2014 at 18:45 Comment(2)
if DEBUG is False, have you verified your ALLOWED_HOSTS in the settings.py?Urbanna
Thank you @GabrielAmram, it was because my ALLOWED_HOSTS didn't have .researchthroughdesign.org in it.Kortneykoruna
S
49

You have to set your website domain as an allowed host. Place this in your ./app/settings/settings.py:

ALLOWED_HOSTS = [".herokuapp.com", ".researchthroughdesign.org"]

In production you can even remove .herokuapp.com

Shaffert answered 10/12, 2014 at 13:20 Comment(3)
After days looking for a solution to my problem, that was it!Unready
Where is the settings.py?Willie
settings.py is inside the settings folder, which is inside the app folder. In my case, I make use of settings/base.py, settings/prod.py, settings/dev.py to separate production setting, development and common settings.Tooth
F
9
heroku config:set DJANGO_ALLOWED_HOSTS=.example.com,example.herokuapp.com
France answered 6/9, 2016 at 9:8 Comment(0)
M
0

It was answered already but I just wanted to add if you are changing the app name on Heroku right after you change the git remote also make sure to do what was answered by @Leo because I was also struggling to why it was showing 400 response on the browser until I found this question.

Merla answered 3/1, 2020 at 3:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.