Hot reload FastAPI and Flask apps on HTML, CSS, and Javascript changes
November 16, 2023 / 5 min read / 3,217 , 1 , 1
Last Updated: May 12, 2024
browser-sync css fastapi flask gunicorn html javascript jinja2 python uvicorn
Getting instant feedback for code changes is essential when developing a web application. Typical workflows for Python web applications involve a hot-reload functionality for the development web server that will automatically restart the server when changes to python files are detected. However, the server will not automatically restart when changes to HTML, CSS, or JavaScript files are detected. When those files are updated, you must manually restart the server for the changes to occur. Moreover, this typical workflow will not automatically refresh your web browser when you update files, so you must manually refresh the web page to see the changes.
In this tutorial, I’ll show you how to automatically hot-reload your FastAPI and Flask projects that use template engines like Jinja with web servers like uvicorn or gunicorn. After reading, you will be able to automatically restart your server and refresh your browser when Python, HTML, CSS, and other files change—no manual intervention required.