Home > Blockchain >  Django Heroku Porting
Django Heroku Porting

Time:12-14

Trying to set up Django configurations for a public url.

So I ran this first.

$ echo "web: python manage.py runserver 0.0.0.0:\$PORT" > Procfile
$ git add Procfile
$ git commit -m "Specify the command to run your project"

In Procfile:

web: python manage.py runserver 0.0.0.0:\$PORT 
release: python manage.py migrate

In Settings.py:

PORT = os.getenv("PORT", default="5000")
# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True

DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False'

ALLOWED_HOSTS = ["url"]

In env.:

PORT=5000
SECRET_KEY=value

Was using the above commands and got

(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku config:get PORT
5000
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
3:08:10 PM web.1 |  CommandError: "0.0.0.0:\$PORT" is not a valid port number or address:port pair.
[DONE] Killing all processes with signal  SIGINT
3:08:10 PM web.1 Exited with exit code null

I also used $PORT without the backslash and $. How would I proceed from here to make the public url working.

CommandError: "0.0.0.0:PORT" is not a valid port number or address:port pair does the same thing. 

web: python manage.py runserver 0.0.0.0:5000 will work though for local

CodePudding user response:

Use gunicorn to serve your web application via Heroku as described here:

https://devcenter.heroku.com/articles/python-gunicorn

Regarding your error, I think you're technically escaping the $ and so its not expanding the variable.

Try removing the \ or, for debugging purposes see if this works by hard coding the port you expect to be in $PORT and see if that works, if it does, I imagine you need to set the $PORT env variable.

  • Related