Deploying Flask app to Heroku

后端 未结 1 1903
孤独总比滥情好
孤独总比滥情好 2020-11-30 03:12

I\'m trying to develop my first \"large\" app with Flask on Heroku and I\'m attempting to combine the basic tutorial here: https://devcenter.heroku.com/articles/python with

相关标签:
1条回答
  • 2020-11-30 04:01

    I haven't used Heroku, but to me, it looks like they have a reserved port for Flask, specifically 33507. It looks like it will try to use an environment variable, which I am not sure how to set in Heroku. The good news is you can tell Flask which port to use.

    try this:

    app.run(debug=True, port=33507)
    

    and it looks like adding the PORT to the env in heroku is done like this:

    heroku config:add PORT=33507
    

    You should only have to do one of these. I would try the first as it, to me, is the straight forward way to fix the issue.

    EDIT
    After reading the article from your post, I see where the issue comes in.

    port = int(os.environ.get('PORT', 5000))
    

    That line says, get the value of PORT from the environment if it is set, otherwise use 5000. I am not sure why they wouldn't allow it to run from 5000 if that's what is in their docs, but I would try this change:

    port = int(os.environ.get('PORT', 33507))
    
    0 讨论(0)
提交回复
热议问题