Django Webapp Framework Comparison

WebappFrameworkComparison / Scratchbook / Django

django

Here is my log: http://herbert.poul.at/board/thread/727/?page=1

(it took me two hours to implement this very simple application .. from executing 'startproject' until it was finished. This is not really representative since i already knew django.. but anyway .. it actually shocked me that i needed so long.. it felt much shorter ;) )

1. Screenshots

  • Bar details
  • Edit bar
  • Bar list

2. Evaluation

In WebappFrameworkComparison/Planning i prepared a few questions, so i now try to answer them ...

How easy was the framework to learn ?

N/A - I already knew the framework

How easy was the setup ?

IMHO .. very easy .. but.. i already knew it .. so no surprises (but.. it's really just svn checkout - and creating a symlink to python site-packages)

How easy is the deployment of new versions ?

easy.. update the files.. and reload apache

How extend able is the result ? (e.g. Imagine i would like to add a workflow where changes get online once an administrator approves them)

as easy as it gets ... and most of the times extensions could be done without littering existing code (e.g. through signals like pre/post model save)

How much duplication was necessary ? (e.g. need to describe the models in the database as well as in code or xml ? / need to describe attributes of models in models and views ?, etc.)

well .. i did some duplication because for example the 'details' view is really simplistic .. so i "defined" there again which fields the model has .. but this could be done more generic.. or .. in most cases.. simply "design" this view template ..

How much useless code (code which is the same for every application, view, model, ...) was required

well.. i don't know of any .. i probably could have saved me two lines and used the generic list and details views, instead of writing my own ..

URLs:

How does the mapping of URLs work ?

through regular expressions which map against view functions

this were my url definitions:

urlpatterns = patterns('barcrud.views',
                   (r'^$', 'list'),
                   (r'^create.*$', 'edit'),
                   (r'^edit/(?P<bar_id>\d+)/$', 'edit'),
                   (r'^details/(?P<bar_id>\d+)/$', 'details'),
                   (r'^postcomment/(?P<bar_id>\d+)/$', 'postcomment'),
                   )

How can you link within templates to other actions/views/... ?

unfortunately .. i was too lazy to implement it everywhere the "clean" way .. in a real application it should definitifely be used:

it is possible to make reverse lookups which tries to apply a given set of parameters to the URL patterns .. a typical get_absolute_url method in the model looks like this:

@permalink
def get_absolute_url(self):
    return ('barcrud.views.details', (), { 'bar_id': self.id })

this could also be used for editing urls & co .. and .. you could use named URLs to link to URLs not associated with models..

3. Various Comments

One of the more annoying things when getting started with django is it's template engine (you can of course use another template engine with django..). The reason for this is django's extreme position on forcing the developer / designer to move all and any logic out of templates - This is not necessary good .. or bad .. but requires at least some adjustments if you come from more "powerful" template engines (django template engine is still very powerful - for example the inheritance schema is very useful and allows to create great extend able and customizable applications.).

There is quite some opposition against putting all logic out of the templates (and hence making more developer work necessary, as i understand it) - for example http://www.cmlenz.net/archives/2007/06/logic-in-templates

(I personally have not much problems with this approach.. especially after seeing quite some business logic implemented in velocity & co ;) )

4. Code Examples

Well .. there is not all that much code

4.1. Forms

One especially noteworthy feature of django is it's 'forms' classes ('newforms' actually) which allows an object oriented approach to create forms..

It also allows you to automatically generate forms out of existing models..

For example take a look at the form to create/edit bars (for simplicity i've done it in 'models.py' usually you probably want to put it all in it's own python module):

class BarForm(forms.ModelForm):
    beers = forms.MultipleChoiceField( choices = BeerChoices(),
                                       required = False, )

    class Meta:
        model = Bar
        exclude = ('creationdate', 'editdate', 'lasteditor')

the template would then simply output the form like: {{ form }}

as you can see - because of the object oriented approach you could add custom behavior - like error checking, additional fields/widgets, etc. it is very handy and makes form based applications as easy as it gets.

5. Conclusion

Last Modified: 2008-02-10 20:22:06 by Herbert Poul - [ Snip Changes ] [ Wiki History ]

0 Comments

No comments yet.

Please login to create a new thread.

Personal website and blog of Herbert Poul. Also check out my Photo Gallery.




Herby's Photo Gallery

Subscriptions

User

You are not logged in.
Login
Register