How to send a variable data from server (python file) to an html file if I'm including it with Jinja?

Viewed 74

I'm using Python and Flask to host a website.

Server side code:

'''

@app.route('\')
def home_page():
     return render_template("index.html", year=current_year)

'''

Now in my index.html I have included the footer (this is there for all pages) with Jinja. That is, {% include "footer.html" %}, but I don't know how to pass the year value to the footer.html file.

1 Answers

In footer.html, add:

<p> {{ year }} </P

This will pick the value of year from the homepage() view function.

Related