Login

Tag "templating"

Snippet List

direct to template from a subdir

I needed a way to quickly get a direction of html pages templated such that another person could drop new templates in to a subdirectory and without modifying urls.py or views.py get them up and being displayed. Now, the direct_to_template view provided django.views.generic.simple can sort of do this with a urlpattern like: `url(r'^(?P<template>.*\.html)$', direct_to_template)` But that means your templates, no matter what level in the url hierarchy they are reached at, have to be defined at the root of a template directory. I wanted them retrieved from a specific subdirectory instead so I could provide a little wall for them. Hence this snippet. To use you would have url pattern that looked like: `url(r'^foo/(?P<template>.*\.html)$', direct_to_template, {'subdir' : 'subdir/'}),` Which will template any url that matches <parent url>/foo/bar.html for any 'bar'. The problem is if this is a sub-url pattern match this is going to look for the template "bar.html" when we may actually want it to get the template "<parent url>/foo/bar.html"

  • templating
  • wildcard
  • subdir
Read More

Make anything into a template

This is a quick and dirty way to reuse the Django templating system for your own ends. Just pop in the familiar Django template syntax into whatever content you like and any chunk of content can be a template. This is great if you need to wrap data in HTML (as in for a mass email). The best part about this is that your "template" can now be stored in a database, instead of just in the file system.

  • template
  • templating
Read More

2 snippets posted so far.