Say I have this header.html file
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
{{ random.randrange(0, 5) }}
{% block body %}
{% endblock %}
</body>
</html>
and this main.html file which extends it:
{% extends "header.html" %}
{% block body %}
<p>Hello</p>
{% endblock %}
and this main.py file:
from flask import Flask, render_template
import random
app = Flask(__name__)
@app.route("/")
def main():
return render_template("main.html")
app.run()
Currently when I run this and go to the website it shows a 500 Internal Server Error and I get this error in my python console:
jinja2.exceptions.UndefinedError: 'random' is undefined
How could I be able to somehow 'import' the random library into the header.html template?
I am running