Adders
Adders

Reputation: 665

How would you turn jinja2 templates into static html

I have a flask application using the jinja2 template engine. The content is dynamic, pulling particular bits from a database.

I'd like to turn a particular page static with all the dynamic data etc. intact. However, I'd like this to run every hour or so as the database will continue to have new data, hench why I'm not just using an existing static generator or building the static page manually - I will cron the job to run automatically.

Any thoughts on how this might be done? I can't provide code examples as I simply don't have a clue on how I might tackle this.

Any help to get me started would be much appreciated.

Upvotes: 0

Views: 861

Answers (1)

davidism
davidism

Reputation: 127180

You can use Frozen-Flask to convert a dynamic Flask app to a static site. It can discover most pages on it's own, assuming each page is linked from another page, such as a list of blog posts linking to individual posts. There are also ways to tell it about other pages if they are not discovered automatically. You could run this periodically with a cron job to update the static site regularly.

freeze_app.py:

from flask_frozen import Freezer
from myapp import app

freezer = Freezer(app)
freezer.freeze()

Upvotes: 1

Related Questions