【问题标题】:Unable to render file links (FileColumn) in Django-Tables2无法在 Django-Tables2 中呈现文件链接(FileColumn)
【发布时间】:2014-06-06 09:55:15
【问题描述】:

我正在使用 Django-Tables2 呈现一个表格,其中的列是:IDFile

我的表定义在tables.py:

class FileTable(tables.Table):
    id = tables.Column(verbose_name="ID")
    f = tables.FileColumn(verose_name="File")

这是我要发送给FileTable的内容:

q1 ={
     id = model.id,  # String, type(model.id) == 'str'
     file = model.file  #FieldFile, type(model.file) == <class 'django.db.models.fields.files.FieldFile'>
     }

     table = FileTable([q1])
     RequestConfig(request, paginate={"per_page": 25}).configure(table)

     ....

问题是 Django 一直将我的 Filecomlum 呈现为“-”:

|       ID         |File|
|------------------|----|
|DKWPRODSORWPDSKROT|  - |
|------------------|----|
|VLPQIENDJASO940D1O|  - |

我试图跟随 django-tables2 documentation 但它没有任何工作示例,我不知道出了什么问题。

感谢任何建议。

【问题讨论】:

    标签: python django file


    【解决方案1】:

    找到我的问题所在! 创建类FileTable时,我将文件属性定义为 f 但在我的 q1 字典上(我用来调用表类) 文件属性称为field。因此键 f 显示为 null。

    因此,在为 django-tables2 创建表类时,请确保 dict 属性被称为类属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2020-08-24
      相关资源
      最近更新 更多