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, 4 months ago
  2. Automatic CRUD urls from your models... by codigodaniel 1 year, 1 month ago
  3. Decorator that limits request methods by schinckel 2 years, 6 months ago
  4. Django 1.2+ template loader for Jinja2 by SimonSapin 1 year, 8 months ago
  5. Allow any view (probably a generic view) to accept captured URL variables into extra_context. by orblivion 1 year, 3 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?)