缩小HTML输出的简单Django模板加载器。

django-template-minifying-loader的Python项目详细描述


django应用程序,提供简单的模板加载程序。它通过去掉html和django模板标记之间的空白字符来减少模板中的html输出。这是与django 1.10一起工作的django-template-minifier的更新。

注意事项:

安装

pip install django-template-minifying-loader

基本用法

修改django项目设置的模块。

用于生产(注意缓存的加载程序):

TEMPLATES=[{'DIRS':[str(APPS_DIR.path('templates')),],'OPTIONS':{'loaders':['django.template.loaders.cached.Loader','template_minifying_loader.loaders.filesystem.Loader','template_minifying_loader.loaders.app_directories.Loader',],},},]

用于开发(每次刷新重新加载模板):

TEMPLATES=[{'DIRS':[str(APPS_DIR.path('templates')),],'OPTIONS':{'loaders':['template_minifying_loader.loaders.filesystem.Loader','template_minifying_loader.loaders.app_directories.Loader',],},},]

很高兴在你的模板中有更少的空间和新行!

高级用法:

使用修改的设置,您可以: *关闭在HTML标记之间剥离空格

TEMPLATE_MINIFIER_HTML_TAGS=False# default = True
  • 关闭django模板标记(s{%,%}s)之间的分隔符
TEMPLATE_MINIFIER_TEMPLATE_TAGS=False# default = True
  • 关闭所有剥离功能
TEMPLATE_MINIFIER=False# default = True
  • 运行自己的strip_函数,该函数对模板进行预处理
TEMPLATE_MINIFER_STRIP_FUNCTION='template_minifier.utils.strip_spaces_in_template'

(变量名称有误,请参见2了解详细信息)

  • 仅在生产中使用
ifDEBUG:TEMPLATE_MINIFIER=False

已知问题:

  • 不要在内联javascript<;script>;或.js模板中使用//one line注释。在某些情况下,如果您在那里使用了大量{%if%},它可以注释掉};或},例如:
// comment something - !!it's evil!!
{%if%}functionname(){}{%endif%}

使用/**/代替

/* comment something - it's nice and clean <3! */{%if%}functionname(){}{%endif%}

或者只设置template_minifier_template_tags=false

待办事项:

  • {%new_line%}模板标记

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用(BluetoothGattCharacteristic)特性中的数据创建、写入和保存csv文件。getValue()   java如何使用groupBy创建一个值为BigDecimal字段平均值的映射?   日期时间Java将iso_即时格式的字符串转换为日期   java如何检索和显示Android firebase的配置文件?   scala AWSJAVASDK:解压缩大小必须小于262144000字节   要应用于列表的java JSTL if条件   java在3个点之间画一个正方形   Kotlin java抽象类IllegaAccessError   java原语双值相等取决于大小?   java有没有一种方法可以对数据集使用compareTo()方法,而不必遍历数据集的每个元素?   java为什么我发送的每个UDP消息都会改变端口源?   重新选择文件时swing Java JTree冻结   java不知道我的游戏是怎么回事   Motif L&F中自定义组合框渲染器中的Java Swing消失文本   java Trade Me API访问前的OAuth