一套django模板工具。
项目描述
一套简单工具,可以让您在django模板中使用更轻松。基于优秀的django-classytags库。
安装
安装包
$> pip install django-template-goodies
将“template_goodies”添加到INSTALLED_APPS。
用法:render_with & def_block 和 use_block
这是一个类似宏的解决方案,允许您定义一个始终看起来相同的基模板,并在其中仅填充不同的“块”。
假设您有部分模板person_wrapper.html
{% load goodies %}
<div class="person-wrapper">
<div class="first-name">{{ first_name }}</div>
{% use_block "block" %}
</div>
您可以使用以下方式使用它
{% load goodies %}
{% render_with "person_wrapper.html" first_name="First" last_name="Last" %}
{% def_block "block" %}
<div class="last-name">{{ last_name }}</div>
{% end %}
{% end %}
此调用将用“{% use_block “block” %}”替换person_wrapper.html中的内容,并在“render_with”内部使用“{% def_block …. %}”和“{% end %}”。所以上面的结果大致如下
<div class="person-wrapper">
<div class="first-name">First</div>
<div class="last-name">Last</div>
</div>
另一个表格的例子,table.html
{% load goodies %}
<table class="{{ opts.table_class }}">
<thead>
<tr>
{% use_block "headers" %}
</tr>
</thead>
<tbody>
{% for row in object_list %}
<tr>
{% use_block "row" %}
</tr>
{% endfor %}
</tbody>
</table>
可以以下方式使用
{% render_with "table.html" object_list=people %}{% def_block "headers" %}
<td>ID</td>
<td>First name</td>
<td>Last Name</td>
<td>Age</td>
{% end %}{% def_block "row" %}
<td>{{ forloop.counter }}</td>
<td>{{ row.first_name }}</td>
<td>{{ row.last_name }}</td>
<td>{{ row.age }}</td>
{% end %}{% end %}
用法:dict
更新或创建模板内的字典。如果需要,您可以在变量上使用所有类型的过滤器
{% load goodies %}
{% dict opts name="first"|title %}
{% dict opts last_name="last" value=opts.name %}
{{ opts.first }} - {{ opts.last_name}} || {{ opts.value }}
结果大致如下
First - last || first
要求
django-classytags
项目详情
关闭
django_template_goodies-0.1.5.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 415f322e8ba9a69ff18a4a698928a12ea654541ae1ba3493950472d41cf05f79 |
|
| MD5 | 72046578aa7ae070fb98bc69ea5d3f5c |
|
| BLAKE2b-256 | d02350962757f1de9d7cd66fe7ed61ca965169d032af24a2a7cc4da05da3e371 |