Skip to content

Getting started

Minimal GridViewSpec page on Django (same spec API works with Jinja2/Starlette — Backends).

Install

pip install "grid-view-spec[django]"

Django setup

INSTALLED_APPS = ["grid_view_spec.backends.django"]
python manage.py migrate grid_view_spec_django

Mount routes — Django integration:

path("", include("grid_view_spec.backends.django.urls")),

Page assets

{% load grid_view_spec %}
{% grid_view_spec_assets part='css' %}

{% render_grid_view_spec spec rows %}
{% grid_view_spec_assets part='js' force_core=True %}

Charts: load ECharts in the host base template. AG-Grid pages load extra bundles automatically when the spec contains backend="ag_grid" tables — AG-Grid.

First spec page

1. View

from django.shortcuts import render
from grid_view_spec import GridViewSpec, validate_spec
from grid_view_spec.types.layout import GridViewArea, GridViewLayout
from grid_view_spec.types.table_v2 import GridViewColumn, GridViewTable

def orders_list(request):
    rows = [{"name": "Ada", "amount": 120}, {"name": "Bob", "amount": 85}]
    spec = GridViewSpec(
        id="orders",
        blocks=(
            GridViewTable(
                id="orders_table",
                backend="simple",
                columns=(
                    GridViewColumn(id="name", label="Customer", field="name"),
                    GridViewColumn(id="amount", label="Amount", field="amount", type="currency"),
                ),
            ),
        ),
        layout=GridViewLayout(root=GridViewArea(id="root", blocks=("orders_table",))),
    )
    result = validate_spec(spec)
    assert result.ok, [d.message for d in result.diagnostics]
    return render(request, "orders.html", {"spec": spec, "rows": rows})

2. Template

{% load grid_view_spec %}
{% render_grid_view_spec spec rows %}

Client sort, search, and column settings run via gridviewspec.min.js (GridView.bootScope).

Validate

result = validate_spec(spec)
assert result.ok, [d.message for d in result.diagnostics]

IDE: MCP servergridview_validate.

Imports

Need Import
Spec from grid_view_spec import GridViewSpec
Render from grid_view_spec.render import render_grid_view_spec
Wire from grid_view_spec.validate import spec_to_wire, spec_from_wire
Django host from grid_view_spec.backends.django.host import DjangoGridViewHost

Next steps