Categorized: Django

Django Template System Basics

The long way

  1. Load a template
  2. Fill a Context
  3. Return a HttpResponse object

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:

Comments

Nothing to see here yet. Start things off, why don't you?

What do you think about that?

Elsewhere in the empire: Home, Blog, APOD