templateIn Progress2026

Jinja Template Renderer

How AST-Powered Mock Generation Eliminated Manual Test Data for Jinja Templates

At a Glance

Challenge

Previewing Jinja templates required wiring up real backends or writing manual test data

Result

Instant live-reload previews with auto-generated mock data from AST parsing

Tech Stack

PythonJinja2AST parsingFrappe

Status

in-progress

Situation

Frappe developers building custom print formats, email templates, and report layouts in Jinja2 had no way to preview their work without connecting to a real Frappe instance. Testing a template change meant creating real documents in the system, which was slow and cumbersome. Alternatively, developers would write manual JSON mock data files, but keeping them in sync with evolving templates was error-prone and tedious.

The Challenge

Build a standalone renderer that automatically understands what data a Jinja template expects — and generates matching mock data on the fly — so developers can preview and iterate on templates instantly without any backend.

What Was Built

  • Built an AST parser that walks the Jinja2 template tree to extract all variable paths, iterable references, and loop variable mappings — using the actual parser, not fragile regex patterns.

  • Implemented automatic mock data generation: the parser infers variable types from usage context and generates plausible values (strings, numbers, dates, lists) without manual configuration.

  • Created DocMock, a Frappe-aware mock object that simulates Frappe document fields and methods, enabling realistic previews of print formats and report templates.

  • Added a live-reload development server with file watching — changes to templates or data files trigger instant browser refresh via injected polling.

  • Included French-locale number formatting support and JSON context export for debugging and sharing template data.

Results

Template preview setup

Real Frappe instance required

Standalone, zero dependencies

Mock data creation

Manual JSON files

Auto-generated from AST

Feedback loop

Live-reload on file save

Template features

Includes, extends, macros, loops

Frappe template developers now iterate on print formats and reports with instant visual feedback and zero backend dependencies — the tool understands what data each template needs and generates it automatically.

Key Achievement

Live-reload template previewing with auto-generated contextual mock data including Frappe-specific DocMock objects, eliminating all manual test data setup.

Frequently Asked Questions