Flask Programming

Hands On No. 9 : Working with Parameters

Resources

Source Code of hello.py
from flask import Flask
from flask import render_template

app = Flask(__name__, template_folder='templates')

@app.route("/viewdata/")
def index1():
    return render_template('View-Data.html', id=1)

@app.route("/viewdata/<int:id>")
def index(id):
    return render_template('View-Data.html', id=id)

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

Source Code of View-Data.html

<!DOCTYPE html>
<html>
<head>
<title>Data</title>
</head>
<body>
<h1>You have entered {{ id }}</h1>
</body>
</html>

Source Code of 404.html

<!DOCTYPE html>
<html>
<head>
<title>Data</title>
</head>
<body>
<h1>Error in the Data</h1>
</body>
</html>