Django view function design

Posted by dragoon on Stack Overflow See other posts from Stack Overflow or by dragoon
Published on 2010-04-02T18:43:20Z Indexed on 2010/04/02 19:03 UTC
Read the original article Hit count: 364

Filed under:
|
|

Hi, I have the view function in django that written like a dispatcher calling other functions depending on the variable in request.GET, like this:

action = ''
    for act in ('view1', 'view2', 'view3', 'view4', ... ):
        if act in request.GET:
            action = act
            break
...
if action == '':
    response = view0(request, ...)
elif action == 'view1':
    response = view1(request, ...)
elif action == 'view2':
    response = view2(request, ...)
...

The global dispatcher function contains many variable initialization routines and these variables are then used in viewXX functions.

So I feed that this is bad view design but I don't know how I can rewrite it?

© Stack Overflow or respective owner

Related posts about django

Related posts about design