在这种情况下,是否可以为特定页面定制django-tables2模板? [英] Is it possible to custom django-tables2 template for a specific page in this case?

查看:57
本文介绍了在这种情况下,是否可以为特定页面定制django-tables2模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django-tables2在模板中的表中呈现我的数据。.
通过分页可以使一切正常。

I'm using django-tables2 to render my data in tables in the template.. everything is rendered fine with pagination..

设计器我们公司的希望将数据显示更改为块而不是简单表。以下图片可能会解释更多。

The Designer of our company wants to change the Display of data into blocks instead of simple table. the following picture may explain more.

I想问问我是否可以在这种情况下使用Django tables ..因为我不想松开分页

I Want to ask if I can use Django tables2 in this case ..since I don't want to loose the pagination

是否可以自定义 django_tables2 / table.html 文件仅适合这种情况(因为我在项目的许多其他页面中都使用了django-tables2)?

Is it possible to custom the django_tables2/table.html file to only fit this case (because I'm using django-tables2 in many other pages in the project)?

任何其他想法可能会有所帮助。

Any other ideas may be helpful.

预先感谢:)

推荐答案

是的,您可以创建一个自定义模板(基于 django_tables2 / table.html ),并将特定表的模板Meta属性设置为其路径:

Yes, you can create a custom template (based on django_tables2/table.html) and set a specific table's template Meta attribute to its path:

import django_tables2 as tables

class Table(tables.Table):
    # columns

    class Meta:
        template = 'table-blocks.html'

或对<$ c使用 template 参数$ c> Table 构造函数:

or use the template argument to the Table constructor:

table = Table(queryset, template='table-blocks.html')

或使用 {%render_table%}的第二个参数 templatetag:

or use the second argument of the {% render_table %} templatetag:

{% load django_tables2 %}
{% render_table queryset 'table-blocks.html' %}

这篇关于在这种情况下,是否可以为特定页面定制django-tables2模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆