locals() is passed as the context of a Django template
What it finds
render(request, "page.html", locals()) hands every local variable to the template, including ones that were never meant to be shown, and makes it impossible to see from the view what the template uses. A dict that names the values does both.
From the rule's source, django_locals_context.rs.
from django.shortcuts import render def page(request): title = "x" return render(request, "page.html", locals())tx0 reports: locals() gives the template every local variable def other(request): return render(request, "page.html", {"title": "x"}) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:django-locals-context" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:django-locals-context] reason="..."tx0 explain tx0/python:django-locals-context shows the same in the terminal. Found a false positive? Report it.