how to manually assign imagefield in Django

后端 未结 1 927
盖世英雄少女心
盖世英雄少女心 2020-12-03 03:40

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...

相关标签:
1条回答
  • 2020-12-03 03:45

    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)
    
    0 讨论(0)
提交回复
热议问题