DEV Community

Cover image for How to run a flask project on Repl.it? (with a brower preview)
Timothy Huang
Timothy Huang

Posted on

How to run a flask project on Repl.it? (with a brower preview)

Repl.it (https://repl.it/) is a very useful development runtime environment. We can easily run nodejs, php, html, python, ..etc. on repl.it.

But how to run a flask project on repl.it? We can refer to quick start on flask document:

https://flask.palletsprojects.com/en/2.0.x/quickstart/



from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"


Enter fullscreen mode Exit fullscreen mode

But when we push "Run" button on the header area on repl.it, the console start to build and run and exit with nothing, sure, we didn't use flask command to start the program.

Switch to Shell, run:



$ export FLASK_APP=main
$ flask run 
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)


Enter fullscreen mode Exit fullscreen mode

We can find that it starts to listen port 5000, but we can't read the result content.

So, how to read the content? Just put the line on the bottom of these code:



app.run(host='0.0.0.0')


Enter fullscreen mode Exit fullscreen mode

Then push the "Run" button, the web server listen on 0.0.0.0:5000 and start a new window that the browser preview content comes out. It's really convenient to develop python flask project on repl.it.

Image description

The demo project is here:

https://replit.com/@timhuangt/demoflask

Let's play with flask on Repl.it.

Top comments (0)