flask app in python

Here is a basic example of a Flask web application in Python:

main.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()
145 chars
11 lines

In this example, we are creating a Flask object, defining a route for the home page, and returning a simple greeting. The if __name__ == '__main__': block runs the development server when the script is executed directly.

To run the application, save the file with a .py extension and execute it in your terminal with python filename.py. The server should start running on http://localhost:5000/.

gistlibby LogSnag