Search code examples
flaskcloud9-ide

Viewing a Flask app in the Cloud9 Test Browser


I'm creating a web app based on Miguel Grinberg's Flasky app (from his book Flask Web Development).

When running manage.py runserver in the Cloud9 IDE, the command line tells me that it is running at http://127.0.0.1:5000/. However, when I type this IP address into the Cloud9 test browser, I see nothing. https://[workspace]-[username].c9users.io (with or without :5000) doesn't work either.

Here's my manage.py code:

from app import create_app
from flask.ext.script import Manager, Shell

app = create_app('default')
manager = Manager(app)

if __name__ == '__main__':
  manager.run()

Solution

  • This video https://www.youtube.com/watch?v=MI8YIRDeGzU by Chris Lynch outlines the flask configuration settings you need for the Cloud9 browser at around the 7 minute mark. In order to start server hit the green run button near the top of the page to the right of the preview button.

    #Insert the line below to to run on Cloud9    
    app.run(host=os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT', 8080)))
    #end insert, place above __name__ == __main__
    if __name__ == '__main__':
        app.run()
        app.debug(True)