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/