On Fri, Oct 16, 2009 at 12:05 PM, Michael P. Jung <mpj...@terreon.de> wrote:
>
> Some time ago I came up with a decorator to enable rendering jinja2
> templates easily. The decorator 'monkey patches' the request object by
> providing a __getattr__ method and adding some new methods.
>
> https://labs.pyrox.eu/common/jinja2/tree/django.py
>
> This could be easily adapted for django templates, though I'm not a huge
> fan of this solution anymore.
>
>
> I've found it to be way more practical to just store the request object
> inside a threading.local object and let my functions access it directly.
>
> That would allow you to write very simple view functions that don't even
> need the request to be passed as argument.
>
>    from django.http import request
>
>    def index():
>        return response('index.html', user=request.user)
>
>
> A nice side effect of this would be that the whole middleware thing for
> adding lazy fields to the request object becomes obsolete, too. No more
> passing around request objects like a madman in order to access the
> request object inside template tags, filters, ModelAdmins, etc.
>
>
> Getting rid of the superfluous request argument would be more a pony
> request for Django 2.0, as it'd break a lot of code. I like the idea
> nonetheless.
>
>
> --mp
>
> >
>

Quite simply, no.  Storing anything in a threadlocal instead of
passing it around is indicative of bad coding practice, and poor
architecture.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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

Reply via email to