Sunday May 03, 2009

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.

Thursday Nov 13, 2008

Django newbie gotchas

I'm working on a project which makes use of the Django framework. Django is a web framework which abstracts the back-end database away from the python object and view models which use that database. Since (aside for a small netbean project) I've stayed away from web development for several years, I seem to have missed a lot of noise around ASP, Perl and PHP web development. I hope I haven't missed much. From the looks of the internet, It wouldn't surprise me if only half the web-developers out there only understand half of what they know about web development. There is more than a grain of truth in the saying "If cities were built like web sites, the first woodpecker would destroy civilization".

I'm finding Django 1.0 somewhat challenging, but I'm also finding that I can pull off usable web pages and forms without too much trouble. The django documentation is well above average (especially djangobook.com), and the IRC and mailing list communities are active and helpful. I did run into a few gotchas. Here are some of them:

[Read More]
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