python 从django modelhttp://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 从django modelhttp://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-相关的知识,希望对你有一定的参考价值。

e = Entity()
# Using File
f = open('/path/to/file')
e.somefile.save(new_name, File(f))
# Using ContentFile
e.license_file.save(new_name, ContentFile('A string with the file content'))
class Entity(models.Model):
    somefile = model.FileField(upload_to='files')

以上是关于python 从django modelhttp://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-的主要内容,如果未能解决你的问题,请参考以下文章