DEV Community

Cover image for "Python Flask Framework Short Notes with Commands"
BALAKRISHNA S
BALAKRISHNA S

Posted on

"Python Flask Framework Short Notes with Commands"

Image description

Flask is a lightweight web application framework written in Python.
Here are some basic commands and notes for Flask:

1.Install Flask:

pip install Flask
Enter fullscreen mode Exit fullscreen mode

2.Import Flask in your Python file:

from flask import Flask
Enter fullscreen mode Exit fullscreen mode

3.Create a Flask app instance:

app = Flask(__name__)
Enter fullscreen mode Exit fullscreen mode

4.Define a route using the @app.route() decorator:

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

5.Run the Flask app:

if __name__ == '__main__':
    app.run()
Enter fullscreen mode Exit fullscreen mode

6.Access the app in your browser at

http://localhost:5000/
Enter fullscreen mode Exit fullscreen mode

7.To pass variables in a URL, use angle brackets in the route definition:

@app.route('/user/<name>')
def user(name):
    return f'Hello, {name}!'
Enter fullscreen mode Exit fullscreen mode

8.To run the app in debug mode, set the debug parameter to True:

if __name__ == '__main__':
    app.run(debug=True)
Enter fullscreen mode Exit fullscreen mode

These are just the basics of Flask. There are many more features and commands available in the framework.

There is a free Udemy course available for beginners on Python Flask at the following link:
https://www.udemy.com/course/python-flask-for-beginners/

Top comments (0)