开发者

Bind shorter var names in django template

To the risk of being closed as duplicate (I can't really find it...) I have the f开发者_如何学Goollowing question. I am sure it's either under my nose, or not possible, but I prefer to ask.

Is it possible to bind to multiple, shorter variable names in django? I know the existence of with, but with assumes you open a block. I would like to bind three or four, meaning that I would have to open (and close) four with blocks. Feasible, but not very nice.

Example, say I have this in my context: foo.bar.baz.quux1, foo.bar.baz.quux2, foo.bar.baz.quux3. I would like to bind them to quux1, quux2 and quux3 for easier access.


No, there isn't a built-in way. You could do this in the view, or write a shortcut method on foo. Alternatively a custom template tag could do it.


{% with foo.bar.baz.quux3 as quux3 %}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜