2010-02-14 26 views

Trả lời

4
from django.template.loader import get_template_from_string 

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

Từ [Django 1,8 docs] (https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/# get-template-from-string): "API riêng' get_template_from_string (template_code) 'đã bị xóa trong Django 1.8 vì ..." – natevw

22

Dựa trên the docs cho việc sử dụng hệ thống mẫu:

from django.template import Template, Context 

t = Template("My name is {{ my_name }}.") 
c = Context({"my_name": "Adrian"}) 
t.render(c) 
Các vấn đề liên quan