views:

64

answers:

3

I think that is the right way to ask it. I'm wondering which parts of the code execute first, second, etc.

My assumption would be, but I don't know:

  1. Request
  2. Middleware
  3. View
  4. Model
  5. Middleware
  6. Response

The reason I'm asking is because I want something to happen dynamicall in the Model based on a request variable and I'm trying to device the best way to automatically add the request in to the model layer without passing in via the views. I would assume that some sort of middleware fantastic contraption would be the way to do it somehow.

A: 

Neither the model nor the templates are ever part of the stack. Do your work in a view.

Ignacio Vazquez-Abrams
will you change your answer by one character so I can vote it up. It says I can't vote it lol.
orokusaki
+1  A: 

I think it's more like:

  1. Request
  2. Middleware (URL mapper)
  3. View
    1. Model (if requested by the view)
    2. Template (if requested by the view)
  4. Middleware (response output)
tylerl
+4  A: 

To answer your clarification comment -- You can't get there from here.

models.py is just a file where you put model classes, which are just classes that get accessed from all over the place. Unless the request object is passed to the function you're working with, then it does not exist, and there is no request.user. Models can be used from anywhere, not just from within contexts where there's a request.

If you need to work with the request object, then pass it as a parameter. And if that doesn't make sense, then you're using your model wrong.

tylerl