Introduction

Use Django’s template engines to render static files that are collected during the collectstatic routine and likely served above Django at runtime. Files rendered by django-render-static are immediately available to participate in the normal static file collection pipeline.

For example, a frequently occurring pattern that violates the DRY principle is the presence of defines, or enum like structures in server side Python code that are simply replicated in client side JavaScript. Another example might be rebuilding Django URLs from arguments in a Single Page Application. Single-sourcing these structures by transpiling client side code from the server side code keeps the stack bone DRY.

django-render-static includes Python to Javascript transpilers for:
  • Django’s reverse function (urls_to_js)

  • PEP 435 style Python enumerations (enums_to_js)

  • Plain data define-like structures in Python classes and modules (defines_to_js)

django-render-static also formalizes the concept of a package-time or deployment-time static file rendering step. It piggybacks off the existing templating engines and configurations and should therefore be familiar to Django developers. It supports both standard Django templating and Jinja templates and allows contexts to be specified in python, json or YAML.

You can report bugs and discuss features on the issues page.

Contributions are encouraged! Especially additional template tags and filters!