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 4 years, 7 months ago
  2. Limit queryset to objects related to parent in ManyToMany fields within admin inlines by DrMeers 2 years, 11 months ago
  3. Handy tag for generating URLs to media files by Amr Mostafa 6 years, 1 month ago
  4. Allow any view (probably a generic view) to accept POST variables into extra_context by orblivion 2 years, 6 months ago
  5. Django 1.2+ template loader for Jinja2 by SimonSapin 2 years, 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?)