python - 使用 django-tables2 呈现带有字典列表的表行时遇到问题
问题描述
我在通过使用 django-tables2 传递字典列表来呈现表格行时遇到问题。
views.py
========
list_of_dict = [{"File Path": 'path1', "Age": 500, "No of files": 90},
{"File Path": 'path2', "Age": 400, "No of files": 25}]
nt = Small_table(list_of_dict)
RequestConfig(request).configure(nt)
return render(request, "collectionsec.html", {"small": nt})
tables.py
=========
import django_tables2 as tables
class Small_table (tables.Table):
name = tables.Column()
age = tables.Column()
nof = tables.Column()
class meta:
attrs = {'class': 'paleblue'}
attrs = {'class': 'table table-responsive', 'width': '100%'}
collectionsec.html
==================
{% load django_tables2 %}
{% render_table small %}
这是输出的样子:
Name Age Nof
— — —
— — —
有人可以帮我吗?
提前致谢 :)
解决方案
找出问题所在!内部类应该命名为“元”而不是我的“元”
推荐阅读
- functional-programming - 我的程序给了我警告(程序的主模块是空的:运行时什么都不会发生)
- python - 如何使 ndimage.filters.maximum_filter 像 MATLAB 的 imregionalmax 函数一样工作?
- java - 如何从具有多维数组的列表视图中获取值?
- java - maven 中缺少子依赖的解决方法
- c++ - 在带有 Visual Studio 2017 的 Windows 上使用 CGAL 和 Boost 时编译错误
- r - 按因子对柱条施加正态分布
- c# - 如何更改图像源,在 GUI 中显示并在之后运行一些代码?
- spring-kafka - Kafka消费者健康检查
- spring - 如何以个人方式配置spring-ioc依赖注入?
- spring-boot - Spring Boot 2 Actuator Starter 中的 Nullpointer w。Tomcat指标