Posts

Showing posts with the label flask

From Beginner to Intermediate: Exploring Flask's Features with a Task Manager App

Image
  Here's an example of an intermediate-level Flask app that incorporates more features and functionality: python Copy code from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) # Sample data tasks = [] @app.route( '/' ) def index (): return render_template( 'index.html' , tasks=tasks) @app.route( '/add' , methods=[ 'POST' ] ) def add_task (): task = request.form[ 'task' ] tasks.append(task) return redirect(url_for( 'index' )) @app.route( '/delete/<int:task_id>' ) def delete_task ( task_id ): if task_id < len (tasks): del tasks[task_id] return redirect(url_for( 'index' )) if __name__ == '__main__' : app.run(debug= True ) In this example, we have an app that allows users to add and delete tasks. Here's an overview of the functionality: The index() function renders the index.html template and passes the tas...