2010-02-14 10 views

Respuesta

4
from django.template.loader import get_template_from_string 

tpl = Template(get_template_from_string("My name is {{ my_name }}.")) 
+4

A partir de los [Django 1,8 docs] (https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/# get-template-from-string): "API privada' get_template_from_string (template_code) 'fue eliminada en Django 1.8 porque ..." – natevw

22

Basado en la the docs para usar el sistema de plantillas:

from django.template import Template, Context 

t = Template("My name is {{ my_name }}.") 
c = Context({"my_name": "Adrian"}) 
t.render(c) 
Cuestiones relacionadas