why django document does not specify how to use non-global middleware

109 views
Skip to first unread message

DanYun Liu

unread,
Apr 25, 2012, 12:26:04 PM4/25/12
to django...@googlegroups.com
I am new to django, before django I used struts2 to build web application. It is common that we need to apply some middleware to a part of views and others not. I didn't find any userful information on the django site, so I searched the stackoverflow and got the right answer.


I will be useful to people who is familiar struts but new to django  to include how to user non-global middleware when introuduce the midlleware.


--
Pursuit the freedom of the soul.

Marcin Tustin

unread,
Apr 25, 2012, 12:50:30 PM4/25/12
to django...@googlegroups.com
Just because you used to do it in Struts, it does not mean that it is the best, or even a good, way to do it in django.

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



--
Marcin Tustin
Tel: 07773 787 105

Tom Evans

unread,
Apr 26, 2012, 4:34:05 AM4/26/12
to django...@googlegroups.com
On Wed, Apr 25, 2012 at 5:50 PM, Marcin Tustin <marcin...@gmail.com> wrote:
> Just because you used to do it in Struts, it does not mean that it is the
> best, or even a good, way to do it in django.
>

That's not true, certainly not in this case. A commonly used feature
in Django is the ability to add view decorators to a view. These can
intercept the request before calling the view function, modify the
request, call a different function, modify the response returned, etc.
A single view function can be decorated by many decorators, each
calling the next in a middleware-like chain.

In fact, middleware is so analogous with decorators that there is an
adaptor function that ships with django that turns a middleware class
into a decorator that can be applied to a single view - I think it is
called 'decorator_from_middleware'.

Given that, I would say that view decorators are Django's equivalent
of per view middleware.

In the world of web development, there is little that is new and
revolutionary, simply because they all solve similar goals. A piece of
technology in one framework is likely to inspire similar features in
another framework.

What one framework may call something may not be what another
framework does, and users moving between frameworks don't need to be
belittled just because they do not know how that framework names
things.

Cheers

Tom

Marcin Tustin

unread,
Apr 26, 2012, 7:20:49 AM4/26/12
to django...@googlegroups.com
On Thu, Apr 26, 2012 at 09:34, Tom Evans <teva...@googlemail.com> wrote:
What one framework may call something may not be what another
framework does, and users moving between frameworks don't need to be
belittled just because they do not know how that framework names
things.


If you are saying that I have belittled the OP, you should withdraw that accusation, or show that it is in fact the case that all struts development practices should be copied in Django. 
 
--
Marcin Tustin

Tom Evans

unread,
Apr 26, 2012, 7:29:04 AM4/26/12
to django...@googlegroups.com
I stand by everything I said.

If I had received that reply from you I would have felt belittled, and
I said nothing about "all struts development practices", only
"per-view middleware", which is a common feature of many frameworks,
including both Django and struts.

Tom

Marcin Tustin

unread,
Apr 26, 2012, 7:33:23 AM4/26/12
to django...@googlegroups.com
Y

No, *I* was the one who referred to all struts development practices. It remains the case that just because someone is used to doing something in struts, it does not follow that they should be doing that in Django. You may be so sensitive that you find it belittling to be told something like that, but by no objective standard can it be called belittling. 

I will be complaining to the list administrators. The only abusive behaviour has come from you, slandering me.
 
--
Marcin Tustin


Russell Keith-Magee

unread,
Apr 26, 2012, 7:51:38 PM4/26/12
to django...@googlegroups.com
Ok - I think everyone needs to settle down a little bit.

I've just re-read the whole thread. Here's my summary:

The OP didn't post a question - they posted a source of information that they thought might be helpful for someone coming from a Struts background.

Marcin gave a one line response. The content of your response is completely accurate as general advice -- just because one framework does something one way doesn't mean every framework should do the same thing. However, in being terse, you've also missed an important detail -- the fact that different frameworks use the English language in different ways, and what Struts calls middleware may well be a good match for what Django calls a view decorator.

Tom gave a detailed response, drawing attention to this fact.

And then the wheels fell off the wagon.

Tom, you possibly overshot the mark a little by saying that Marcin belittled the OP. I completely agree with you that Marcin's comments could easily be *perceived* as belittling, especially to a newcomer to the list. However, by the same token, being called on being belittling when that wasn't your intent could itself be perceived as belittling, which is what I suspect is the source of Marcin's anger.

Marcin -- it's an unfortunate fact that on mailing lists, terse responses often appear to be rude or belittling, even if that wasn't your intent. On top of that, your original advice is 100% correct, but quite possibly almost completely irrelevant to the OP's point -- which is what Tom pointed out. You also can't control how other people perceive your words, and Tom is letting you know that if *he* had read your words, he would have felt belittled (a point which he clarifies very well in his second response).

We won't tolerate ad hominem attacks (or any other sort of attack, for that matter) on Django mailing lists. In this case, I think we've just got a minor misunderstanding of intent, exacerbated by some terse responses. So - lets chalk this one up to experience and move on.

Yours,
Russ Magee %-)



On Thursday, 26 April 2012 at 7:33 PM, Marcin Tustin wrote:

> Y
>
> On Thu, Apr 26, 2012 at 12:29, Tom Evans <teva...@googlemail.com (mailto:teva...@googlemail.com)> wrote:
> > On Thu, Apr 26, 2012 at 12:20 PM, Marcin Tustin <marcin...@gmail.com (mailto:marcin...@gmail.com)> wrote:
> > > On Thu, Apr 26, 2012 at 09:34, Tom Evans <teva...@googlemail.com (mailto:teva...@googlemail.com)> wrote:
> > > >
> > > > What one framework may call something may not be what another
> > > > framework does, and users moving between frameworks don't need to be
> > > > belittled just because they do not know how that framework names
> > > > things.
> > >
> > >
> > > If you are saying that I have belittled the OP, you should withdraw that
> > > accusation, or show that it is in fact the case that all struts development
> > > practices should be copied in Django.
> >
> >
> > I stand by everything I said.
> >
> > If I had received that reply from you I would have felt belittled, and
> > I said nothing about "all struts development practices", only
> > "per-view middleware", which is a common feature of many frameworks,
> > including both Django and struts.
>
>
> No, *I* was the one who referred to all struts development practices. It remains the case that just because someone is used to doing something in struts, it does not follow that they should be doing that in Django. You may be so sensitive that you find it belittling to be told something like that, but by no objective standard can it be called belittling.
>
> I will be complaining to the list administrators. The only abusive behaviour has come from you, slandering me.
>
>
> --
> Marcin Tustin
>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com (mailto:django...@googlegroups.com).
> To unsubscribe from this group, send email to django-users...@googlegroups.com (mailto:django-users...@googlegroups.com).
Reply all
Reply to author
Forward
0 new messages