Gilang Chandrasa Thoughts, stories, and ideas

Rendering Template from String on Django Template

Render template from a string.

from django.template import Context
from django.template import Template

template = Template('My name is, {{ name }}!')
context = Context({'name': 'Gilang'})
template.render(context)

Use context from context processors.

from  django.template import RequestContext
from django.template import Template

def hello_view(request):
    template = Template('{% now "d M Y" %}, Login as {{ user }}')
    rendered_template = template.render(RequestContext(request))