Search code examples
pythonherokudnsnamecheap

Having issues linking my domain on Namecheap with Heroku django (python) app


I have followed through a lot of articles on how to do this and believe I have followed it through well enough.

I bought a domain name example.com from Namecheap and added to my heroku app, copied the custom DNS from Heroku and added to my namecheap domain settings like so: screenshot of Namecheap dashboard

But whenever I visit my custom domain, I get a Bad Request (400) on my screen and my heroku logs shows:


2019-06-25T16:36:51.564888+00:00 app[web.1]: 10.11.247.75 - - [25/Jun/2019:16:36:51 +0000] "GET / HTTP/1.1" 400 26 "-" "Mozilla/5.0 (Linux; Android 6.0; Infinix HOT 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Mobile Safari/537.36"
2019-06-25T16:36:51.568697+00:00 heroku[router]: at=info method=GET path="/" host=www.coleruche.com request_id=459dbc14-b837-404a-893e-0e80d1d763cb fwd="105.112.50.227,66.249.93.222" dyno=web.1 connect=0ms service=20ms status=400 bytes=199 protocol=http
2019-06-25T16:36:52.191660+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=www.coleruche.com request_id=d2df8bb7-c41a-43dd-9c5f-3f964ea14c9f fwd="105.112.50.227,66.249.93.208" dyno=web.1 connect=0ms service=16ms status=400 bytes=199 protocol=http
2019-06-25T16:36:52.193341+00:00 app[web.1]: 10.93.215.14 - - [25/Jun/2019:16:36:52 +0000] "GET /favicon.ico HTTP/1.1" 400 26 "http://www.coleruche.com/" "Mozilla/5.0 (Linux; Android 6.0; Infinix HOT 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Mobile Safari/537.36"

But then when I go to the heroku domain for my app, eg example.herokuapp.com, everything works well.

I believe this means I linked it well enough and my heroku app gets the request, but I can't say much from the error logged out. Why the 400 error? The app is a django (Python) app and I have installed WhiteNoise and those other packages needed, it runs on heroku/python buildpack.


Solution

  • I suspect you need to add you domain to Django's ALLOWED_HOSTS, e.g.

    ALLOWED_HOSTS = ['.example.com']