1

I need to access the root url of my Heroku app. I have several apps for this project (e.g., staging, production) and I'd like to programmatically set this value in my settings file. What I want is:

URL_ROOT = 'http://silly-name-1234.herokuapp.com'

As suggested here, I have tried the following:

import socket
HOSTNAME = socket.gethostname()
URL_ROOT = HOSTNAME

But, this doesn't seem to work

Community
  • 1
  • 1
Rob
  • 313
  • 1
  • 3
  • 11

2 Answers2

1

You should do

heroku config:add BASE_IRI=http://silly-name-1234.herokuapp.com at the heroku cli

after that do a os.environ.get('BASE_IRI', 'localhost') in your settings.py

Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65
  • Thanks! This worked well. I also found this Heroku documentation to be useful: https://devcenter.heroku.com/articles/config-vars – Rob Oct 24 '12 at 15:13
  • What does the IRI stand for? BASE_IRI seems an unusual choice. – dgh Jan 17 '13 at 04:58
  • Yeah I found it in some places. It comes from the non-English part of the world. It is URI (Uniform resource identifier) internationalized beyond ascii to unicode standards for URIs in Arabic, Chinese et al. http://en.wikipedia.org/wiki/Internationalized_Resource_Identifier – Pratik Mandrekar Jan 17 '13 at 06:16
-1

Try os.environ.get('HOSTNAME')

Rag Sagar
  • 2,314
  • 1
  • 18
  • 21