Re: [Feature Request] extra_context -> dataclass

2022-04-06 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Template contexts are namespaces, for which a dictionary is an ideal type. If you want type safety with dicts, you can use TypedDict in type hints. You haven't presented any advantage to using dataclasses, plus it doesn't seem that inconvenient to add your own wrapper that calls asdict(). On Wed,

[Feature Request] extra_context -> dataclass

2022-04-06 Thread Arthur
Hi all! Currently django views do not accept dataclasses as context. I stumbled about this because I wanted to do something like this: @cached_property def extra_context(self): data = MyDataClass(...) ... return data Unfortunately, this is unpacked by get_context_data and throws a