Posts from May 2008

Getting RequestContext in Your Templates

May 10, 2008 | code, django | 10 comments

Lately, we’ve been taking over projects from people who began building their first site in Django, but either got in over their head or just found they didn’t have the time to continue. As I review the existing code, the first issue I typically see is using the render_to_response shortcut without including the RequestContext, preventing context processors from being used in the templates. The standard symptom is when people can’t access MEDIA_URL in their templates.

Here are a few ways to add RequestContext to your templates.

Option #1: Adding RequestContext to render_to_response

The Django documentation recommends passing RequestContext as an argument to render_to_response like this:

from django.shortcuts import render_to_response
from django.template import RequestContext

def my_view(request):
    # View code here...
    return render_to_response('my_template.html',
                              my_data_dictionary,
                              context_instance=RequestContext(request))

This works, but as you can see, it adds a fair amount of repetitive code to your views ...

Full post →

Thanks for checking in on our blog today. Want to learn more about Lincoln Loop? Visit our home page.

Categories

Archives

Elsewhere

What I’ve been up to online

  • #5247: patch6702.diff - Django Code - Trac
    08.08.04, 20:30 #
  • #5247: patch.diff - Django Code - Trac
    08.08.04, 20:30 #
  • Anybody want to split a hotel room for #DjangoCon?
    08.07.31, 9:42 #
  • Just got confirmation I'm on the invite list for #DjangoCon. Being a member does have its benefits. Couch surf or hotel?
    08.07.31, 9:02 #
  • Admin Image Widget
    08.07.31, 6:28 #
  • Follow @trailmapping for Trailmapping.com updates. Just pushed some slick jQuery into production tonight.
    08.07.31, 1:53 #
  • Munin :: com :: djangoproject.com :: trac_tickets
    Graphs of trac tickets for Django
    08.07.29, 12:00 #
  • Automating tests in Django | Eric's Site
    Generate tests by simply clicking through your development site.
    08.07.24, 9:23 #
  • Creator/updater fields for admin
    08.07.21, 16:16 #
  • fairview computing :: Django geography hacks
    Nice base for a reusable Locations app for Django
    08.07.10, 16:58 #
  • working with a designer
    Great tips on how to be a good client to your designer and get the most out of him at the same time.
    08.07.09, 23:45 #
  • Fluency Admin at deanjrobinson.com
    Elegant WordPress admin interface
    08.07.09, 16:43 #
  • Search Docs with Shortwave
    08.07.08, 5:00 #
  • django-chunks - Google Code
    Handy little project for managing CMS content snippets.
    08.07.07, 16:53 #
  • Norbauer Inc: The Boston Ruby on Rails Development Consulting Firm
    I love 1 page websites. Short, sweet and to-the-point.
    08.07.02, 9:21 #

Interested in working with us?
Fill out the form below or contact us at:

PO Box 774441
Steamboat Springs, CO
80477

970.879.8810
info@lincolnloop.com