python默认图片_python – Django ImageField默认

models.py:

class UserProfile(models.Model):

photo = models.ImageField(upload_to = get_upload_file_name,

storage = OverwriteStorage(),

default = os.path.join(settings.STATIC_ROOT,'images','generic_profile_photo.jpg'),

height_field = 'photo_height',

width_field = 'photo_width')

photo_height = models.PositiveIntegerField(blank = True, default = 0)

photo_width = models.PositiveIntegerField(blank = True, default = 0)

views.py:

def EditProfile(request):

register_generator()

source_file = UserProfile.objects.get(user = request.user).photo

args = {}

args.update(csrf(request))

args.update({'source_file' : source_file})

我的模板中的某处

{% generateimage 'user_profile:thumbnail' source=source_file %}

我收到一个错误:

UserProfile匹配查询不存在.

在这一行:

source_file = UserProfile.objects.get(user = request.user).photo

问题是ImageField的默认属性不起作用.因此,我的模型中没有创建对象.如何正确使用这个贡献?如果我忽略这个属性,那么创建对象就没有错误.我需要通过绝对或相对路径吗?

我正在使用django-imagekit来调整图像的大小,然后再分配它:http://django-imagekit.readthedocs.org/en/latest/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值