Django framework, a good balance of convenience and dicipline

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.

Comments:

Post a Comment:
Comments are closed for this entry.
About

bnitz

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today