locals() is passed as the context of a Django template

tx0/python:django-locals-contextstrictwarningsecurity

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.

Example from the rule's tests
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"})
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.