Categorized: Django
Django Template System Basics
The long way
- Load a template
- Fill a
Context - Return a
HttpResponseobject
Like so:
from django.template import Template, Context
from django.http import HttpResponse
...
t = get_template('current_datetime.html')
html = t.render(Context({'current_date': now}))
return HttpResponse(html)
The short way: render_to_response
Like so:
from django.shortcuts import render_to_response
...
return render_to_response('current_datetime.html', {'current_date': now})
Source:
- The Django Book (pages 51, 52 of the print edition)
Comments
Nothing to see here yet. Start things off, why don't you?
What do you think about that?