SlideShare a Scribd company logo
Flask Application
PRESENTATION ON:
Introduction to Flask:
 Flask is a micro-framework for Python.
 It is lightweight and easy to use, ideal for small to medium web applications.
 Flask is often used for developing RESTful APIs, websites, and web services.
Flask Application Structure
 Common File Structure:
 /static (CSS, JS, images)
 /templates (HTML templates)
 /app.py (main Flask application)
 /requirements.txt (dependencies)
 /config.py (configuration settings)
Creating a Simple Flask Application:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
•app = Flask(__name__) initializes the app.
•@app.route('/') creates a route for the
homepage.
•app.run(debug=True) runs the app with the
debug mode on.
Routing in Flask:
•Routes are used to map URLs to functions.
•Example of a dynamic route:
@app.route('/user/<username>’)
def show_user(username):
return f'Hello, {username}!'
Template Rendering with Jinja:
Flask uses Jinja templating engine.
Templates allow dynamic HTML generation.
<!-- Example: hello.html -->
<h1>Hello, {{ name }}!</h1>
In Flask:
from flask import render_template
@app.route('/greet/<name>’)
def greet(name):
return render_template('hello.html', name=name)
Flask and Database Integration:
•Flask supports several databases via extensions like:
•Flask-MySql connector (SQL databases)
•Flask-MongoEngine (NoSQL, MongoDB)
•Example with MySql Connector:
import mysql.connector
from flask import Flask
app = Flask(__name__)
def get_db_connection():
connection = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='your_database'
)
return connection
Create a Table:
@app.route('/create_table')
def create_table():
connection = get_db_connection()
cursor = connection.cursor()
# Create a new table
cursor.execute("""CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY,name VARCHAR(100),email VARCHAR(100) ) """)
connection.commit()
cursor.close()
connection.close()
return "Table created successfully!"
Insert Data:
@app.route('/insert')
def insert_data():
connection = get_db_connection()
cursor = connection.cursor()
# Insert data into the table
cursor.execute("""
INSERT INTO users (name, email)
VALUES (%s, %s)
""", ('John Doe', 'john@example.com'))
connection.commit()
cursor.close()
connection.close()
return "Data inserted successfully!"
Read Data:
@app.route('/fetch')
def fetch_data():
connection = get_db_connection()
cursor = connection.cursor()
# Fetch all rows from the table
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
cursor.close()
connection.close()
return str(rows)
Update Data:
@app.route('/update')
def update_data():
connection = get_db_connection()
cursor = connection.cursor()
# Update user data
cursor.execute("""UPDATE users SET email = %s WHERE name = %s
""", ('newemail@example.com', 'John Doe'))
connection.commit()
cursor.close()
connection.close()
return "Data updated successfully!"
Delete Data:
@app.route('/delete')
def delete_data():
connection = get_db_connection()
cursor = connection.cursor()
# Delete a record
cursor.execute("DELETE FROM users WHERE name = %s", ('John Doe',))
connection.commit()
cursor.close()
connection.close()
return "Data deleted successfully!"

More Related Content

PPTX
This is the js ppt where I have design about class 2 of the js
ODP
Exploring Symfony's Code
PPTX
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
PPTX
Flask & Flask-restx
PDF
Phinx talk
PPTX
SW Security Lec4 Securing architecture.pptx
PPTX
Flask-Python
PPT
RESTful API In Node Js using Express
This is the js ppt where I have design about class 2 of the js
Exploring Symfony's Code
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
Flask & Flask-restx
Phinx talk
SW Security Lec4 Securing architecture.pptx
Flask-Python
RESTful API In Node Js using Express

Similar to Flask Application ppt to understand the flask (20)

PDF
Php summary
PDF
Cocoapods and Most common used library in Swift
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
PPTX
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
PDF
How to execute an oracle stored procedure with nested table as a parameter fr...
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
PPTX
CHAPTER six DataBase Driven Websites.pptx
PDF
Getting to know Laravel 5
PDF
Node.js with MySQL.pdf
PPT
PHP - Getting good with MySQL part II
PPTX
Quick and Easy Development with Node.js and Couchbase Server
PPT
Php Data Objects
PDF
URLProtocol
PDF
Play Framework: async I/O with Java and Scala
PDF
phptut4
PDF
phptut4
PPTX
working with PHP & DB's
PDF
Flask and Angular: An approach to build robust platforms
PPT
PHP and MySQL
Php summary
Cocoapods and Most common used library in Swift
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
How to execute an oracle stored procedure with nested table as a parameter fr...
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
CHAPTER six DataBase Driven Websites.pptx
Getting to know Laravel 5
Node.js with MySQL.pdf
PHP - Getting good with MySQL part II
Quick and Easy Development with Node.js and Couchbase Server
Php Data Objects
URLProtocol
Play Framework: async I/O with Java and Scala
phptut4
phptut4
working with PHP & DB's
Flask and Angular: An approach to build robust platforms
PHP and MySQL
Ad

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Welding lecture in detail for understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT 4 Total Quality Management .pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
web development for engineering and engineering
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPT
Project quality management in manufacturing
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Model Code of Practice - Construction Work - 21102022 .pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Welding lecture in detail for understanding
Digital Logic Computer Design lecture notes
UNIT 4 Total Quality Management .pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
web development for engineering and engineering
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CH1 Production IntroductoryConcepts.pptx
Project quality management in manufacturing
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
bas. eng. economics group 4 presentation 1.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Ad

Flask Application ppt to understand the flask

  • 2. Introduction to Flask:  Flask is a micro-framework for Python.  It is lightweight and easy to use, ideal for small to medium web applications.  Flask is often used for developing RESTful APIs, websites, and web services.
  • 3. Flask Application Structure  Common File Structure:  /static (CSS, JS, images)  /templates (HTML templates)  /app.py (main Flask application)  /requirements.txt (dependencies)  /config.py (configuration settings)
  • 4. Creating a Simple Flask Application: from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return "Hello, World!" if __name__ == '__main__': app.run(debug=True) •app = Flask(__name__) initializes the app. •@app.route('/') creates a route for the homepage. •app.run(debug=True) runs the app with the debug mode on.
  • 5. Routing in Flask: •Routes are used to map URLs to functions. •Example of a dynamic route: @app.route('/user/<username>’) def show_user(username): return f'Hello, {username}!'
  • 6. Template Rendering with Jinja: Flask uses Jinja templating engine. Templates allow dynamic HTML generation. <!-- Example: hello.html --> <h1>Hello, {{ name }}!</h1> In Flask: from flask import render_template @app.route('/greet/<name>’) def greet(name): return render_template('hello.html', name=name)
  • 7. Flask and Database Integration: •Flask supports several databases via extensions like: •Flask-MySql connector (SQL databases) •Flask-MongoEngine (NoSQL, MongoDB) •Example with MySql Connector: import mysql.connector from flask import Flask app = Flask(__name__) def get_db_connection(): connection = mysql.connector.connect( host='localhost', user='your_username', password='your_password', database='your_database' ) return connection
  • 8. Create a Table: @app.route('/create_table') def create_table(): connection = get_db_connection() cursor = connection.cursor() # Create a new table cursor.execute("""CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY,name VARCHAR(100),email VARCHAR(100) ) """) connection.commit() cursor.close() connection.close() return "Table created successfully!"
  • 9. Insert Data: @app.route('/insert') def insert_data(): connection = get_db_connection() cursor = connection.cursor() # Insert data into the table cursor.execute(""" INSERT INTO users (name, email) VALUES (%s, %s) """, ('John Doe', 'john@example.com')) connection.commit() cursor.close() connection.close() return "Data inserted successfully!"
  • 10. Read Data: @app.route('/fetch') def fetch_data(): connection = get_db_connection() cursor = connection.cursor() # Fetch all rows from the table cursor.execute("SELECT * FROM users") rows = cursor.fetchall() cursor.close() connection.close() return str(rows)
  • 11. Update Data: @app.route('/update') def update_data(): connection = get_db_connection() cursor = connection.cursor() # Update user data cursor.execute("""UPDATE users SET email = %s WHERE name = %s """, ('newemail@example.com', 'John Doe')) connection.commit() cursor.close() connection.close() return "Data updated successfully!"
  • 12. Delete Data: @app.route('/delete') def delete_data(): connection = get_db_connection() cursor = connection.cursor() # Delete a record cursor.execute("DELETE FROM users WHERE name = %s", ('John Doe',)) connection.commit() cursor.close() connection.close() return "Data deleted successfully!"