[英]Use Django templates and tags without the rest of Django
I want to use Django for templating, but am not building a web-app. 我想使用Django进行模板化,但我没有构建一个Web应用程序。 Basically, most of my question has been asked and answered here . 基本上,我的大部分问题都在这里被提出并回答。 But I also need to use a certain tag, which is not a custom tag by me (as addressed in one of the answers), but the mathfilters
filters installed with pip
. 但我还需要使用某个标签,这不是我的自定义标签(如其中一个答案中所述),但是使用pip
安装的mathfilters
过滤器。 How can I use them in this context? 我如何在这种情况下使用它们?
I read everywhere to rather use something like Jinja
for this, but that would be a last resort. 我到处读到宁可使用Jinja
这样的东西,但这是最后的选择。
settings.configure()
accepts settings as keyword arguments. settings.configure()
接受设置作为关键字参数。 To activate mathfilters
, simply add it to INSTALLED_APP
like you would do in settings.py
: 要激活mathfilters
,只需将其添加到INSTALLED_APP
就像在settings.py
:
import django
from django.conf import settings
settings.configure(INSTALLED_APPS=['mathfilters'])
django.setup()
Then you can use {% load mathfilters %}
to load the tags and filters. 然后,您可以使用{% load mathfilters %}
来加载标记和过滤器。 Note that since Django 1.7 you need to call django.setup()
after you've configured your settings. 请注意,自Django 1.7起,您需要在配置设置后调用django.setup()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.