Flask for Beginners – Intern Learning Guide
This PDF is designed for beginner interns who are starting backend development using Python
Flask. It explains concepts in simple language with examples.
1. What is Flask?
Flask is a lightweight web framework written in Python. It is used to build web applications and APIs
easily. Flask is called a micro-framework because it does not force you to use specific tools or
libraries.
2. Why Use Flask?
- Easy to learn for beginners
- Flexible and lightweight
- Perfect for small projects and APIs
- Used in real-world production systems
3. Installing Flask
First, make sure Python is installed.
Command:
pip install flask
4. Your First Flask App
Below is a simple Flask application that prints Hello World in the browser.
from flask import Flask
app = Flask(__name__)
@[Link]('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
[Link](debug=True)
Explanation
Flask(__name__) creates the app.
@[Link]('/') defines the URL.
home() runs when the URL is accessed.
debug=True helps during development.
5. Routing in Flask
Routing means mapping URLs to functions.
@[Link]('/about')
def about():
return 'About Page'
6. HTTP Methods
Flask supports GET, POST, PUT, DELETE methods.
@[Link]('/login', methods=['GET', 'POST'])
def login():
return 'Login Page'
7. Templates (HTML Rendering)
Flask uses Jinja2 templates to render HTML pages.
from flask import render_template
@[Link]('/home')
def home():
return render_template('[Link]')
8. Handling Forms
Flask can read form data using request object.
from flask import request
@[Link]('/submit', methods=['POST'])
def submit():
name = [Link]['name']
return name
9. JSON and APIs
Flask is widely used to build REST APIs.
from flask import jsonify
@[Link]('/api/data')
def data():
return jsonify({'status': 'success'})
10. Project Structure
Typical Flask project structure:
project/
[Link]
templates/
static/
11. Debugging Tips
- Always run in debug mode during development
- Check error messages in terminal
- Use print statements for learning
12. What to Learn Next
- Flask Blueprints
- Database (SQLite, PostgreSQL)
- Authentication
- Deployment
Happy Learning!
Practice daily and build small projects to master Flask.