views:

56

answers:

3

I've been getting more and more interested in using Pylons as my Python web framework and I like the idea of MVC but, coming from a background of never using 'frameworks/design patterns/ what ever it\'s called', I don't really know how to approach it.

From what I've read in the Pylons Book, so far, it seems I do the following:

  • Create my routes in ./config/routes.py
    This is where I map URLs to controllers.

  • Create a controller for the URL
    This is where the main body of the code lies. It does all the work and prepares it for viewing

  • Create my template
    I create a template and assign the data from the controller to it

Models... I have no idea what they're for :/

So my question is, can you recommend any reading materials for someone who clearly has no idea what they're doing?

I really want to start using Pylons but I think in a few months time I'll come back to my code and think "...what the F was I thinking :/"

EDIT: A better, summarized, question came to mind:

What code should be placed in the Controller? What code should I put in the Model? The view is just the templating, right?

And, in terms of Pylons, the 'lib' folder will contain code shared among Controllers or misc code that doesn't fit anywhere else - Right?

A: 

Grab some well-written projects with that framework and study its code. It's Python, after all :)

A: 

there is a book about pylons 0.9.7 [http://pylonsbook.com/]. and after that see the updated docs to understand pylons 1 at [http://bitbucket.org/bbangert/quickwiki] and [http://bitbucket.org/bbangert/pylons]. if you have a question go to the google groups for pylons [http://groups.google.com/group/pylons-discuss]

waleed
A: 

Model is for your db-related code. All queries go there, including adding new records/updating existing ones.

Controllers are somewhat ambigous, different projects use different approaches to it. Reddit for example does fair bit of what should be View in controllers.

I, for one, prefer to limit my controllers to request processing and generation of some result object collections, which are then delivered to XHTML/XML/JSON views, depending on the type of request (so each controller should be used for both static page generation and AJAX handling).

I really want to start using Pylons but I think in a few months time I'll come back to my code and think "...what the F was I thinking :/"

Well, thats inevitable, you should try different approaches to find the one which suits you best.

Daniel Kluev