【问题标题】:Attrs not being rendered in HTML using Django-Tables2没有使用 Django-Tables2 在 HTML 中呈现属性
【发布时间】:2020-07-06 03:58:01
【问题描述】:

基于Django-Tables2 documentation,将自定义属性添加到任何列似乎非常简单,我这样做了:

class NameTable(tables.Table):
    name = tables.Column(attrs={"td":{"class":"my-class"}})
    office = tables.Column(attrs={"td":{"class":"my-class2"}})
    class Meta:
        attrs = {"class": "paleblue"}
        template_name = "django_tables2/bootstrap.html"
        fields = ("name", "office")

我通过以下方式将我的数据传递给这个类:

data = [{'name':'John','office':'L.A'},{'name':'Michael','office':'N.Y.'}]
table = NameTable(data)
template_name = 'planning/index.html'
return render(request, template_name, {"table": table})

不幸的是,即使数据在表中正确呈现,我也找不到我之前定义的标签(my-class 和 my-class2),也找不到在元类中定义的类“paleblue”渲染后的 HTML 源代码(这当然意味着没有正确应用 CSS)。

我错过了什么?

【问题讨论】:

  • 刷新浏览器
  • 已经尝试过,甚至在私密浏览中也尝试过
  • 你的代码是正确的,你的模板使用{% render_table table%}?
  • 我真的不知道出了什么问题,但毕竟今天早上一切正常。我怀疑即使在隐身模式下,某些缓存仍在使用中。

标签: python django django-tables2


【解决方案1】:

我用一条建议回复自己:刷新时始终使用 Control+F5 而不是 F5。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    相关资源
    最近更新 更多