【问题标题】:using django-tables2 in dashbord在仪表板中使用 django-tables2
【发布时间】:2021-04-24 02:04:36
【问题描述】:

试图将 django 表放入dashboard.html 页面。我可以在另一个 html 文件中可视化我的表格,但无法修复如何放入仪表板页面

models.py


class Asset(models.Model):
    type = models.ForeignKey(AssetType, on_delete=models.CASCADE)
    lc_phase = models.ForeignKey("Asset_Life_Cycle.LifeCyclePhase", on_delete=models.CASCADE)
    name = models.CharField(max_length=30)
    # BaseSpatialField.srid()
    geom = models.GeometryField()

views.py

from .models import Asset
import django_tables2 as tables



class AssetTable(tables.Table):
    class Meta :
        model = Asset

class AssetTableView(tables.SingleTableView):

    queryset = Asset.objects.all()
    table_class = AssetTable
    template_name = 'deneme.html'

试过了,没用


{% for asset in queryset %}

    <p>Name {{asset.name}} </span> </p>

  {% endfor %}

【问题讨论】:

    标签: django django-templates django-tables2


    【解决方案1】:

    django-tables2 的美妙之处在于您不需要遍历查询集中的所有对象。只需在您的模板中使用以下代码即可显示表格:

    {% load render_table from django_tables2 %}
    
    {% render_table table %}

    【讨论】:

      猜你喜欢
      • 2011-12-31
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 2021-12-27
      • 2011-06-15
      相关资源
      最近更新 更多