Skip to main content

Posts

Showing posts from February, 2023

Flask course for beginners

Important Topics in Flask Routing Flask uses the concept of routing to determine which function to call based on the URL requested by the client. A simple example would be mapping the root URL '/' to a function that returns the home page of a website. The routing mechanism can also include dynamic parts in the URL to capture values and pass them as arguments to the handling function. from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello, World!" @app.route('/greet/<name>') def greet(name): return f"Hello, {name}!" if __name__ == '__main__': app.run() Templates Flask uses the Jinja2 templating engine to generate dynamic HTML content. This allows you to separate the presentation logic from the Python code that generates the data. A template can include variables, loops, and control structures, which get evaluated and replaced with actual values ...