Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django在python类中包含模板标记替换_Python_Django_Django Templates - Fatal编程技术网

Django在python类中包含模板标记替换

Django在python类中包含模板标记替换,python,django,django-templates,Python,Django,Django Templates,我知道有一个Django template标记,允许包含其他模板,如: {% include 'template.html' %} 我想知道我是否可以做同样的事情,但是在一个单独的python类中(不是在HTML模板中) 例如,我知道url标记有一个等价物,如下所示: {% url 'some_url_name' %} -> reverse('some_url_name') 我想你可能在找 在单独的python类中是什么意思?你的例子不是clear@petkostas我的意思是,我可以

我知道有一个Django template标记,允许包含其他模板,如:

{% include 'template.html' %}
我想知道我是否可以做同样的事情,但是在一个单独的python类中(不是在HTML模板中)

例如,我知道url标记有一个等价物,如下所示:

{% url 'some_url_name' %} -> reverse('some_url_name')

我想你可能在找


在单独的python类中是什么意思?你的例子不是clear@petkostas我的意思是,我可以做相同的事情,但不能在HTML模板中做,因为HTML模板使用不同的符号来实现相同的事情。
from django.template.loader import render_to_string
context = {'foo': 'bar'}
rendered_template = render_to_string('template.html', context)