Day 4 of the Anvil Advent Calendar

Build a web app every day until Christmas, with nothing but Python!

Counting Down the Days

It’s here – December has really started, and it’s time to start watching the calendar. How better than to build a Python web app to count the days until Christmas?

Visit the finished result:

Get your own copy of the source code here:

Doing the calculation

The calculation itself is pretty simple, thanks to Python’s datetime library. We can do it all in the browser, in the first page’s __init__ method:

from datetime import date

# ...

christmas_day = date(year=2019, month=12, day=25)
days_til_christmas = (christmas_day -

Displaying it on the page

We use the visual designer to lay out our page, and then write the code:

self.days_lbl.text = "%s days" % days_til_christmas

Choosing a domain name

I used Amazon Route 53 to register, then I followed the DNS settings guide to point it at my Anvil app:

That’s it!

I’ve built and published a web app that counts down until Christmas, with nothing but Python! Plenty of time left over for mulled wine, too…

View the source code:

Give the Gift of Python

Share this post: