Cheetah template engine for Django
Usage
- Use the render_cheetah_response shortcut just as you would use render_to_response
- Use the CheetahTemplate class to render contexts in your views from text or file
News - Now released a version which is the stand alone module django_cheetahtemplates and contains the application of the example below. See the source svn repository for the most up to date code.
Example
Put this in your views
from django_cheetahtemplates import render_cheetah_response,CheetahTemplate
from django.template import Context
from django.http import HttpResponse
def hello(request):
# Use shortcut
return render_cheetah_response('hello.tmpl', {'myvar':'hello world','range':range} )
def hello2(request):
# Create and render context
context = Context({'myvar':'hello'})
context['range'] = range
template = CheetahTemplate(filename='hello.tmpl')
return HttpResponse(template.render(context))Then create hello.tmpl somewhere in your TEMPLATE_DIRS
$myvar #for i in $range(10) $i#slurp #end for
When you go to the url linked to either hello or hello2 you will see this
hello world 0123456789
Capabilities:
- Django context/template rendering compatibility with CheetahTemplate class.
- Shortcut replacement for render_to_response => render_cheetah_response
TODO:
- Cheetah template path search (always defaults to your project directory when trying to include files) Fix: find your template from there with relative links?
- Transfer over filters to cheetah format
- Create URL shortcuts for generic cheetah template views (like 'direct_to_template' in urls.py)