2010-02-14 7 views

Répondre

4
from django.template.loader import get_template_from_string 

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

Des ([Django 1.8 docs] https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/# get-template-from-string): "L'API privée' get_template_from_string (template_code) 'a été supprimée dans Django 1.8 parce que ..." – natevw

22

Basé sur le the docs pour l'utilisation du système de template:

from django.template import Template, Context 

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