Hi Tim,

> I've been trying to figure out how to use a custom subclased
> RequestContext[1] object in my generic views.  Looking at the
> code of django/views/generic/*.py it looks like this class is
> hard-coded in each of the views.
>
>
> Ideally, I'd be able to set something in the settings.py to
> specify my default RequestContext class, but I don't readily see
> a way to go about that short of hacking the
> django.templates.context module.

Generic views are using RequestContext by default;
that's what's 'hardcoded' into generic views.

To 'sublclass' Context, you just write a simple method somewhere in  
your code and give it request as an argument.
Like this:

from myproject.myapp import SomeObject

def get_someobjects_(request):
     someobjects = SomeObject.aobjects.all()
     return {'someobjects': someobjects}

Put this in the file myproject/mycomtextprocessor.py for example.
Then you have to tell django that this is a context processor.
You do it in the settings:

TEMPLATE_CONTEXT_PROCESSORS = (
     'myproject.myapp.mycontextprocessor.get_someobjects',
)

Now every view that has RequestContext(request) as contex_instance like

def some_view(request):
        #...
        return render_to_response('mytemplate.html',
                                                        mydata,
                                                        
context_instance=RequestContext(request))

will automatically include {'someobjects': someobjects}, and you can  
use {{ for someobject in someobjects }} in your templates.

I hope I understood the question right...

-benjamin


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to