[go: up one dir, main page]

0% found this document useful (0 votes)
14 views5 pages

Flask - Assignments - With - Starter - Code

The document outlines various Flask framework assignments, each with a project structure and starter code. It includes examples such as a Hello Flask app, a simple login form, a calculator web app, and more advanced topics like user authentication, RESTful APIs, and deployment. Each assignment focuses on different aspects of Flask development, including session management, form validation, and database integration.

Uploaded by

suyashpandey247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Flask - Assignments - With - Starter - Code

The document outlines various Flask framework assignments, each with a project structure and starter code. It includes examples such as a Hello Flask app, a simple login form, a calculator web app, and more advanced topics like user authentication, RESTful APIs, and deployment. Each assignment focuses on different aspects of Flask development, including session management, form validation, and database integration.

Uploaded by

suyashpandey247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Flask Framework Assignments with Starter Code & Structure

1. Hello Flask App

Project Structure:

- app.py

- templates/

- index.html

- about.html

app.py:

from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")

def home():

return render_template("index.html")

@app.route("/about")

def about():

return render_template("about.html")

if __name__ == "__main__":

app.run(debug=True)

2. Simple Login Form

Project Structure:

- app.py

- templates/

- login.html

- success.html

app.py:
from flask import Flask, render_template, request

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])

def login():

if request.method == "POST":

username = request.form["username"]

password = request.form["password"]

if username == "admin" and password == "123":

return render_template("success.html", user=username)

else:

return "Invalid credentials"

return render_template("login.html")

3. Calculator Web App

Project Structure:

- app.py

- templates/

- calc.html

- result.html

Use form to take two numbers and operation, then return result.

4. Session Tracker

Use Flask session to store and increment a counter each time the user visits.

from flask import Flask, session

app = Flask(__name__)

app.secret_key = 'secret'

@app.route("/")

def visit():
session["count"] = session.get("count", 0) + 1

return f"You visited {session['count']} times"

5. Form Validation (Flask-WTF)

Use Flask-WTF with form validation.

from flask_wtf import FlaskForm

from wtforms import StringField, PasswordField

from wtforms.validators import InputRequired, Email

class RegisterForm(FlaskForm):

email = StringField("Email", validators=[InputRequired(), Email()])

password = PasswordField("Password", validators=[InputRequired()])

6. Todo App (No DB)

Store todos in a list or session and allow add/delete in session.

7. HTML Template Inheritance

Use base.html and extend it using {% extends 'base.html' %}

8. Todo App with SQLite

Use Flask-SQLAlchemy with a Task model. Include routes for CRUD operations.

9. User Authentication System

Use User model with login, logout and session management.

10. Blog Platform

Users can post blogs. One-to-many relationship with SQLAlchemy.

11. Blueprint Modularization

Split app into auth.py, main.py, and register them using Blueprints.

12. Upload and Display Profile Picture

Use request.files and save images to static/uploads.

13. RESTful API with Flask

Create REST API endpoints using Flask or Flask-RESTful.


14. Search Functionality

Use query string (request.args.get) to filter results.

15. JWT Authentication API

Use PyJWT to create login and protected routes.

16. Flask with AJAX (Fetch API)

Project Structure:

- app.py

- static/

- script.js

- templates/

- index.html

Use JavaScript fetch() to send data to Flask backend without page reload.

17. Role-Based Access Control (RBAC)

Add roles to User model and restrict routes using decorators.

@app.route("/admin")

@admin_required

def admin_dashboard():

...

18. Unit Testing Flask App

Use unittest or pytest to test routes.

def test_home(client):

response = client.get('/')

assert b"Welcome" in response.data

19. Deployment on Render or Railway

Export requirements.txt and Procfile.

web: gunicorn app:app


20. Flask + SQLite + Charts

Use Chart.js to visualize data from DB.

Pass data from Flask to JS via template context.

You might also like