Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming a template context key "items" does not work #380

Open
dnet opened this issue Oct 7, 2024 · 1 comment
Open

Naming a template context key "items" does not work #380

dnet opened this issue Oct 7, 2024 · 1 comment

Comments

@dnet
Copy link

dnet commented Oct 7, 2024

Thanks for the interesting project, I have started to experiment with it for an existing internal project. For one of the templates, I named a context key items like this:

@template
class MyTemplate(NamedTuple):
    foo: Bar
    items: List[Qux]

And then in the client code:

<ul>
        {props.objects.map((item) => <li>{item.baz}</li>)}
</ul>

Running manage.py runserver completed without errors, however the page loaded while showing two "empty" <li> items, even though I supplied more than that. If I renamed items to objects the problem went away, so it is probably a naming clash with template.items:

def items(self) -> Any:

I guess it would be nicer to warn users

  • in the documentation with a list of words to avoid and
  • in an error message if someone tries to use such a word.
@silviogutierrez
Copy link
Owner

Nice catch, will keep this open to address it. Rewriting the whole template system soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants