0
0
Flaskframework~5 mins

What is Flask

Choose your learning style9 modes available
Introduction

Flask helps you build websites and web apps easily. It gives you tools to handle web requests and show pages.

You want to create a simple website quickly.
You need a small web app to test ideas or learn web development.
You want to build an API to share data with other apps.
You want full control over how your web app works without extra features.
You want to add web features to a Python program.
Syntax
Flask
from flask import Flask
app = Flask(__name__)

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

Flask(__name__) creates your web app.

@app.route('/') tells Flask what URL to listen to.

Examples
This example shows a simple homepage that says welcome.
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Welcome to my site!'
This example adds a new page at URL '/about'.
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/about')
def about():
    return 'About us page'
This example shows how to return data in JSON format.
Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/data')
def data():
    return jsonify({'name': 'Flask', 'type': 'web framework'})
Sample Program

This is a complete Flask app. When you run it, it starts a web server. Visiting http://localhost:5000/ shows 'Hello, Flask!'.

Flask
from flask import Flask
app = Flask(__name__)

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

if __name__ == '__main__':
    app.run(debug=True)
OutputSuccess
Important Notes

Flask is called a 'microframework' because it keeps things simple and small.

You can add extra features with extensions if needed.

Use debug=True only while developing, not in production.

Summary

Flask helps you build web apps with Python easily.

It listens to web addresses and sends back responses.

Flask is simple but can grow with your needs.