Django - Tips to avoid repeating code in views

Posted by D Roddis on Stack Overflow See other posts from Stack Overflow or by D Roddis
Published on 2010-03-20T09:41:08Z Indexed on 2010/03/20 9:51 UTC
Read the original article Hit count: 275

Filed under:
|
|
|
|

I'm moving from a PHP background into Django development via python, mostly for the sake of tackling a MVC (or MVT) that I feel makes the most sense, although in this pattern I've started to notice a lot of repeated code in my views.

For example, when logged in I have information regarding the user that I would like to appear on every page, although when using render_to_response and in every view this is required I have to grab the information and pass it to the render_to_response function.

I'm wondering what would be the most efficient way to cut down on the duplicate code which would in essence be required in all views in a particular app.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about django

Related posts about dry