1π
Is there something Iβm not seeing or does django simply not have this functionalety?
Django deliberately did not include subscripting (i.e. β¦[β¦]
) or calling methods (the methods are called with no parameters if it is a method (i.e. .β¦(β¦)
), but you can not call methods with parameters in the Django templates).
This is for a good reason: often people doing this, do this when writing complicated expressions in the template. This is not what a template is supposed to do. A template should be given the data in an accessible format such that just enumerating over data, and rendering the data is sufficient.
If you would write (complicated) queries in the Django template, this often also would result in N+1 problems and finally Djangoβs template engine is not extremely fast, so interpreting large chunks of data would produce content in a slow manner, and to make things even worse, the template does not support "streaming", so it is only passed to the client when the template is rendered completely.
If you really want to do this, there is an alternative template engine called JinjaΒ [jinja-doc] that supports these, but regardless, it is not a good idea to do this in the template. You should not fix the template, you should fix the view.