By bnitz on May 03, 2009
Some of the strongest criticisms of Django come from users of PHP or other frameworks which allow you to do almost anything in the templates. This can encourage developers to put business logic into the presentation layer which eventually results in an unmaintainable mess. It's the web2.0 equivalent of a GOTO statement.
But on several occasions while working on SourceJuicer it really would've been handy to be able to store or increment variables or directly access a slightly complicated query in the template. For example, I was attempting to pass a list indexed by an existing column (JobID) into a template when I noticed that there was no way to convert the JobID string to a numeric within the template. Then Luis reminded me that if it seems like you're trying to do too much in the template, you're probably trying to do too much in the template. So I went back to the model and saw that I could add the 'slightly complicated' query to an access method in my model. Django does allow you to access methods from the template but it doesn't allow you to pass parameters to these methods. This seems a reasonable balance between strictness and ease of use. It simplified the code while maintaining good separation between business logic and presentation.