Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mike Owens http://mike.filespanker.com/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Bootstrap Django templates out-of-framework

This is the quickest way I've found to bootstrap Django templates without using the entire framework. This is suited for "plain-python" apps without using all the Django types. You'll probably want to cache the Template returns for each given name, but here's the basics.

   1  
   2  # Kick off django config machinery first
   3  from django.conf import settings
   4  settings.configure(TEMPLATE_DIRS=("/whatever/templates",))
   5  
   6  import django.template
   7  import django.template.loader
   8  
   9  
  10  def render(name, *values):
  11      ctx = django.template.Context()
  12      for d in values:
  13          ctx.push()
  14          ctx.update(d)
  15  
  16      t = django.template.loader.get_template(name)
  17      return t.render(ctx)
  18  
  19  print render('layout.tmpl', dict(title='User'), dict(name='Bob', gender='M'))
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS