Quickly check templates while sketching them out

1
2
3
4
5
6
7
8
from django.shortcuts import render_to_response
from django.utils.datastructures import MultiValueDict

def direct_to_template(request, template, **kwargs):
    params = MultiValueDict()
    params.update(kwargs)
    params.update(request.GET)
    return render_to_response(template % kwargs, params)

More like this

  1. direct to template from a subdir by Scanner 3 years, 7 months ago
  2. Allow any view (probably a generic view) to accept captured URL variables into extra_context. by orblivion 1 year, 7 months ago
  3. Automatic CRUD urls from your models... by codigodaniel 1 year, 4 months ago
  4. Allow any view (probably a generic view) to accept POST variables into extra_context by orblivion 1 year, 7 months ago
  5. Django 1.2+ template loader for Jinja2 by SimonSapin 1 year, 11 months ago

Comments

SmileyChris (on April 23, 2007):

Pretty neat!

Unless you need to pass the template name to your context, you could also just do:

if settings.DEBUG:
    # Direct Templates
    urlpatterns += patterns('misc',
        (r'^template/(.*)$', 'direct_to_template')),
)

#

(Forgotten your password?)