Search⌘ K

Solution: Separate HTML Templates

Explore how to improve a Flask web application by separating HTML templates from view logic. Understand using render_template for cleaner code and managing titles within each template for better structure.

We'll cover the following...

The complete implementation of the problem is provided below. Let’s take a look at it!

Solution #

"""Flask Application for Paws Rescue Center."""
from flask import Flask, render_template
app = Flask(__name__)


@app.route("/")
def homepage():
    """View function for Home Page."""
    return render_template("home.html")


@app.route("/about")
def about():
    """View function for About Page."""
    return render_template("about.html")


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=3000)
...