-->
Update Your Footer Python Example / Dynamic Footer Year Python Example

Update Your Footer Python Example / Dynamic Footer Year Python Example

Back to top

Updated by Ashirafu Kibalama on April 02, 2024

Learn how to effortlessly update your footer with the current year using Python's datetime module.






Python offers elegant solutions to update the website footer year dynamically without manual intervention. 

In this blog post, we'll explore several dynamic footer Python examples. 

By leveraging Python's versatility and simplicity, you can ensure that your website's footer stays current, reflecting the latest year automatically. 

Let's elevate your footer game to new heights!

What Is a Footer in Python?


In Python, a "footer" typically refers to a section of code or text appended to the end of a document, script, or output. 

It often provides additional information, disclaimers, copyright notices, or other relevant details.

A footer in Python can take various forms depending on the context: 

An example of a Footer in Python Code.


<!-- Footer -->

<section id="footer" class="gradient-background">
<hr>
<div class="container">

<footer class="row row-cols-1 row-cols-sm-2 row-cols-md-5 py-5 mt-5 ">

<div class="col mb-3">

</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Home</a></li>

</ul>
</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">About</a></li>

</ul>
</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Contact Us</a></li>

</ul>
</div>
</footer>
</div>
<div class="small text-center text-muted fst-italic">Copyright &copy; freepythonsourcecode.com {{current-year}}</div>

</section>
<!-- Footer Ends -->


What Is a Dynamic Footer Year?


A dynamic footer year is a technique commonly used in web development or document generation where the year displayed in the footer updates automatically based on the current date. 

It's a good practice to ensure that the copyright or other time-sensitive information in the footer of a document or webpage is always up-to-date without requiring manual intervention. 

An example requiring a manual intervention: 


<div class="small text-center text-muted fst-italic">Copyright &copy; Your Website 2023</div>

This can be achieved using a placeholder or script that dynamically fetches and inserts the current year into the footer text. 

An example of using a placeholder or script that dynamically fetches the current year flask python:



<div class="small text-center text-muted fst-italic">Copyright &copy; freepythonsourcecode.com {{current-year}}</div>


By doing so, the footer will display the current year dynamically whenever someone views the document or webpage. 

Web developers often use client-side scripting languages like JavaScript or server-side technologies like PHP or Python to implement dynamic footer years. 

These languages can retrieve the current year from the user's system or server and update the footer accordingly. 

This saves time and effort while ensuring the footer's information is always accurate and up-to-date.

Here's a basic example of how you might update your footer year in Python dynamically: 


# for the main.py

#import datetime
from datetime import datetime


# about route
@app.route("/about")
def about():
# SETTING AND UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY
right_year = datetime.now().year # UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY

return render_template("about.html", current-year=right_year)

#contact route
@app.route("/contact", methods=['GET', 'POST'])
def contact():
# SETTING AND UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY
right_year = datetime.now().year # UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY

### OTHER CODES ###
return render_template("contact.html", current-year=right_year)

#login route
@app.route('/login', methods=["GET", "POST"])
def login():
# SETTING AND UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY
right_year = datetime.now().year # UPDATING CURRENT YEAR IN THE FOOTER AUTOMATICALLY

### OTHER CODES ###
return render_template("login.html", current-year=right_year)

# for the footer.html


<!-- Footer -->

<section id="footer" class="gradient-background">
<hr>
<div class="container">

<footer class="row row-cols-1 row-cols-sm-2 row-cols-md-5 py-5 mt-5 ">


<div class="col mb-3">

</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Home</a></li>

</ul>
</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">About</a></li>

</ul>
</div>

<div class="col mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-body-secondary">Contact Us</a></li>

</ul>
</div>
</footer>
</div>

<div class="small text-center text-muted fst-italic">Copyright &copy; freepythonsourcecode.com {{current-year}}</div>

</section>
<!-- Footer Ends -->

To summarise, our blog post emphasized the usefulness and effectiveness of using dynamic footer years in Python, demonstrating a working example. 

We would appreciate your input on how well this explanation clarifies the concept of dynamic footer years in Python and whether it satisfies your implementation requirements.