Both questions answered very helpfully.

Thank you very much!

- Richard

On Apr 26, 12:29 pm, Darryl Ross <[EMAIL PROTECTED]> wrote:
> Richard Atkinson wrote:
> > Hello all! Been lurking for a while, this is my first post.
>
> Welcome!
>
> > I understand that RequestContext is required in order to access  
> > {{ MEDIA_URL }} in templates. I have two questions related to this.
>
> > 1. Please could somebody give an example of how to pass RequestContext  
> > to a generic view from urls.py (sorry if it is in the documentation,  
> > but I couldn't find it).
>
> Generic views use RequestContext, so you don't need to do anything
> special. It's only views you write yourself which you need to handle
> specially.
>
> > 2. Given that I have applications with views that I'd like not to care  
> > about template issues, is there a nice way to specify using  
> > RequestContext by default (maybe from settings.py), without writing  
> > anything in my applications?
>
> If you find yourself doing something over and over again, in Python it
> is easy to abstract that out into a separate function. I find I want to
> use RequestContext in all my views, so instead of the following code:
>
> ----- <<< -----
>   from django.shortcuts import render_to_response
>   from django.template import RequestContext
>
>   def my_view(request):
>       # ...
>       return render_to_response(template, context_vars,
>                                 context_instance=RequestContext(request))
> ----- <<< -----
>
> I abstract out the render_to_response call into a separate function and
> use that in my own views. I create a top level folder called 'helpers'
> which is where I put various bits and pieces. Inside that I create a
> views.py file which has view helpers. My code then becomes:
>
> ----- <<< -----
> ### helpers/views.py
>   from django.shortcuts import render_to_response
>   from django.template import RequestContext
>
>   def render_template(request, template, context_vars={}):
>       return render_to_response(template, context_vars,
>
>                                 context_instance=RequestContext(request))
>
> ### views.py
>   from helpers import render_template
>
>   def my_view(request)
>       # ...
>       return render_template(request, template, context_vars)
> ----- <<< -----
>
> Hope that gives you some ideas.
>
> Regards
> Darryl
>
>  signature.asc
> 1KDownload
--~--~---------~--~----~------------~-------~--~----~
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