Is it better to perform logical conditions in view or template?
I'm starting to learn Django and I'm completely new to the MVC/MTV (whatever you want to call it) playground.
In Django templates can perform logical conditions and filters. I want to know from a performance standpoint, is it better to do the conditions in the view or on the template itself.
I actually find my self more comfortable with doing everything behind t开发者_StackOverflowhe scenes and if there is no difference in terms of performance, then I'd rather do it from the view.
I suggest separating your logic in the following way:
Implement the logic belonging to what your application is doing under the hood in your Django handlers. It usually covers most of your logic.
Implement only the logic belonging to the actual presentation in your HTML templates. For example you can put you logic selecting different styles for various rows of a table based on a complex condition (not just odd/even) or so.
It worked pretty well for me.
精彩评论