Getting Started with Flask
Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.
Installation
pip install flask
pip install flask-sqlalchemy
Your First Route
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, MotaDev!'
if __name__ == '__main__':
app.run(debug=True)
Working with Templates
Flask uses Jinja2 as its templating engine. Create a templates/ folder and add HTML files.
from flask import render_template
@app.route('/about')
def about():
return render_template('about.html', title='About Us')
Database Integration
Using SQLite3 with Flask is straightforward:
import sqlite3
def get_db():
conn = sqlite3.connect('app.db')
conn.row_factory = sqlite3.Row
return conn
Conclusion
Flask gives you the freedom to structure your project however you want. Start small, stay modular, and scale as you grow.
"Flask is fun and easy to learn." — Flask docs
0 Comments
Join the conversation
No comments yet. Be the first!