如何在Django中手动分配imagefield [英] how to manually assign imagefield in Django
本文介绍了如何在Django中手动分配imagefield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
请参阅django文档 django.core.files.File
其中fd是一个打开的文件对象:
model_instance.image_field.save 'filename.jpeg',fd.read(),True)
I have a model that has an ImageField. How can I manually assign an imagefile to it? I want it to treat it like any other uploaded file...
解决方案
See the django docs for django.core.files.File
Where fd is an open file object:
model_instance.image_field.save('filename.jpeg', fd.read(), True)
这篇关于如何在Django中手动分配imagefield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文