Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Genericized pre/post-request processing in Controller?(View?) [RSS Feed]

#1 March 25, 2008 19:15:55

Chris C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Genericized pre/post-request processing in Controller?(View?)


Here's a question that is probably divisive - why did Django decide to go
with Model/Template/View instead of Model/View/Controller? MVC just
conceptually makes so much more sense to me.

Anyhow, that's not the primary point of this posting...

Is there any way to implement some sort of pre and/or post-request
processing that runs across any request that comes through? Does this
already exist? Ideally I would use this to implement some sort of RESTful
interface(yes, I know about the Django REST interfacehttp://code.google.com/p/django-rest-interface/but I don't like that it
seems to violate DRY by requiring you to write extremely similar code for
each of your models - and the fact that you have to define one url per view
type per model. If you had four view types
(XML, JSON, HTML, plaintext) and five models, things get messy and hard to
maintain quick!)

Either way, I am wondering if there is some sort of start/end method similar
to what other frameworks provide? At least in perl Catalyst I know that you
can define a global start and end method that are wrapped around any
request. I would use these methods to start developing my idea for a
genericized RESTful API that you can easily add any model to.

Thanks, Pythonistas!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 March 25, 2008 19:39:24

Malcolm T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Genericized pre/post-request processing in Controller?(View?)


On Tue, 2008-03-25 at 14:04 -0400, Chris Czub wrote:
> Here's a question that is probably divisive - why did Django decide to
> go with Model/Template/View instead of Model/View/Controller? MVC just
> conceptually makes so much more sense to me.

Apart from the fact that you can't do MVC for most web-based
application, since the view can't be asynchronously updated when the
model changes (the link from the model to notify interested views is an
important component of MVC, after all)? :-)

If we modify to what people think of as "MVC" for the web (in any of the
myriad of definitions that are floating around), you can fairly easily
write Django apps in a style such that you can point to certain
functions and say "this is a 'V'", "this is the 'C'". Just have what
Django calls views dispatch the presentation collecting portions to
other function calls. Those other function calls are your big-V views
and the Django view is your Controller. In fact, I'd recommend that for
any non-trivial applications.


> Either way, I am wondering if there is some sort of start/end method
> similar to what other frameworks provide? At least in perl Catalyst I
> know that you can define a global start and end method that are
> wrapped around any request.

A small example of the information flow you're after might help, but
let's see what we can do.. There are things that run before view
processing and after views and before the request is returned -- that's
what middleware is for -- but it's probably not the appropriate place to
be doing any REST management.

If you wanted to do that, you'd route all your URLs of a particular form
to a view, which then becomes the gateway through which everything must
pass, in and out, for those URLs -- thus becoming both the initial and
final method. It's pretty easy to then map those URL fragments onto
model methods if that's the way you want to go. That's probably the sort
of thing you're after here: routing all requests to a particular
collection of URLs through one code path.

That approach works quite well. It's completely in line with how Django
request/response paths flow and managing code even for quite complex
apps is easy. You don't want anything like to all the time, since
Django's models are not MVC models: big-M models model a larger
component with the business state and logic, which could involve a few
pieces of persistent storage -- a.k.a multiple Django models -- for a
start. But if you just want to map HTTP URLs to Django model methods,
it's a dozen lines in a view (expand as requirements necessitate).

Regards,
Malcolm

--
Quantum mechanics: the dreams stuff is made of.http://www.pointy-stick.com/blog/--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » Genericized pre/post-request processing in Controller?(View?) [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support