On Oct 19, 5:20 am, Keith <keithentzer...@gmail.com> wrote:
> I'm writing some code that does something like...
>
> 1. check url for specific information
> 2. do some logic based on named group
> 3. pass results along on request
>
> It is easy for me to do this through urls.py for a single request.
> However, i want to perform this for every request.
>
> I am going down the path of creating a custom middleware that will
> perform my logic as mentioned.
>
> My problem is with how to pass the results along on the request.
>
> My intuition is to try and add a parameter like so...
>
>                 q = request.GET.copy();
>                 q.__setitem__('new_key', 'new_val')
>                 request.GET = q
>
> Only problem is that the code further down the pipe doesn't recognize
> 'new_key' as being available in the request.GET querydict.
>
> please advise.
>
> thanks.

Why do they need to be in the GET dictionary? If you want to add
custom information that will remain available throughout the request
process, just add an attribute to the request object itself:
request.new_key = 'new_val'.

(BTW, I wouldn't recommend using __setitem__ for anything - this is an
internal method, you should just do q['new_key']. But don't do this
anyway, as I say above.)
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to