create flask app in python

To create a Flask app in Python, you can follow these steps:

  1. Install Flask by running pip install flask in your command prompt or terminal.

  2. Create a new Python file called app.py (or any other name you like) and import Flask:

main.py
from flask import Flask
app = Flask(__name__)
46 chars
3 lines
  1. Define a route for your app:
main.py
@app.route('/')
def hello():
    return 'Hello, World!'
56 chars
4 lines
  1. Run the app:
main.py
if __name__ == '__main__':
    app.run()
41 chars
3 lines
  1. Open your browser and go to http://localhost:5000 (or any other port number that you specified in the app.run() method).

You should see the message "Hello, World!" displayed in your browser. You can now add more routes and functionality to your app as needed.

gistlibby LogSnag