Heroku: How to integrate static site generation with Python / Flask Heroku: How to integrate static site generation with Python / Flask flask flask

Heroku: How to integrate static site generation with Python / Flask


Instead of relying on Flask to serve your static blog content, you can run a web server (such as nginx) that routes your traffic to either the Flask website or the static blog content.

User Request -> https://example.org -> nginx -> flask

User Request -> https://example.org/blog -> nginx -> static content (hosted on nginx server or other location)


You can automate step 3 by adding a Heroku Buildpack. There are third party open-source buildpacks for Hugo available on Github, e.g. roperzh/heroku-buildpack-hugo. Alternatively, you could use a Git hook to build the blog every time you commit any changes.

You could probably avoid steps 4 and 5 by setting baseURL and publishDir Hugo configuration settings.

I'm not sure what step 2 entails, but your overall setup (6. & 7.) seems reasonable.