Django FileField (or ImageField) open() method returns None for valid file?

后端 未结 4 963
花落未央
花落未央 2021-02-02 08:42

let me put it like this:

model.py:

class Task(models.Model):
    ...
    seq_file = models.FileField(upload_to=\'files/\', blank=True, null=True)
    ...         


        
4条回答
  •  日久生厌
    2021-02-02 09:10

    because open method of models.FileField doesn't return anything

    you can just use:

    task.seq_file.read()
    

    and you don't need calculate path of file for checking if file exist. you can use task.seq_file.path:

    if not os.path.isfile(task.seq_file.path):
        ....
    

提交回复
热议问题