This Python script minifies HTML in Django templates while preserving Django template tags such as {% %}, {{ }}, and {# #}.
- Minifies HTML content while preserving Django template syntax.
- Accepts input and output file paths as command-line arguments.
- Optimizes Django templates by removing unnecessary whitespace and reducing file size.
- Python 3.6+
htmlminpackage
-
Clone this repository:
git clone https://github.com/hoshmandent/django-html-minifier.git cd django-html-minifier -
Install the required dependencies:
pip install -r requirements.txt
Run the script from the command line, passing the input and output file paths as arguments:
python minify_django_html.py /path/to/input/template.html /path/to/output/minified_template.htmlFor example, to minify a Django template:
python minify_django_html.py admin/templates/theme_bar.html admin/templates/theme_bar.min.htmlThis will read the theme_bar.html file, minify the HTML content, and save the result as theme_bar.min.html.
This project is licensed under the MIT License - see the LICENSE file for details.