django - 无法连接 'str' 和 'ImageFieldFile' 对象 Django

标签 django

无法连接“str”和“ImageFieldFile”对象

filename = settings.MEDIA_ROOT + self.image 

在 Debian Linux 服务器上运行 Python 2.5 (Django 1.3)。

最佳答案

使用image.name:

filename = self.image.name

If you wanted to retrieve the uploaded file's on-disk filename, or the file's size, you could use the name and size attributes respectively; for more information on the available attributes and methods, see the File class reference and the Managing files topic guide.

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField

关于django - 无法连接 'str' 和 'ImageFieldFile' 对象 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6175906/

相关文章:

python - Django 中的对象未保存到购物车

Django Rest Framework - 更新外键

python - 如何在 Django 的单元测试期间禁用翻译?

python - Django 立即保存并返回对象(使用自定义 pk)

django - reverse_set 长度上的过滤模型

Python-Order a list 使得X在Y之后,Y在X之后

管理中的 Django 图像插入

django-cacheops 与 aws redis 加密

python - Django 模型和 Python 类属性

django - 如何使用 Django 测试框架测试 404 NOT FOUND?