Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在django管理端裁剪图像?_Django_Image_Crop - Fatal编程技术网

如何在django管理端裁剪图像?

如何在django管理端裁剪图像?,django,image,crop,Django,Image,Crop,我想在django管理站点中添加一个图像裁剪功能。我不知道我如何才能做到这一点。我使用了django图像裁剪应用程序,但无法将其集成到管理端 您应该在模型中定义save()方法: class MyImage(models.Model): image = models.ImageField(...) image_crop = models.ImageField(blank=True) def save(): super(MyImage, self).save() #will

我想在django管理站点中添加一个图像裁剪功能。我不知道我如何才能做到这一点。我使用了django图像裁剪应用程序,但无法将其集成到管理端

您应该在模型中定义save()方法:

class MyImage(models.Model):
  image = models.ImageField(...)
  image_crop = models.ImageField(blank=True)

  def save():
    super(MyImage, self).save() #will save only image, image_corp will be blank.

    image_path = self.image.path #path to your non croped image

    #now you can load image file and crop it usung PIL and save.

    self.image_crop = 'path/to/cropped/image' #add path to cropped image.
    super(MyImage, self).save() #save data.

相关:。已经经历了这些,但没有在django管理端实现的想法。您需要返回并接受前面8个问题的一些答案“无法集成”是。。。不太准确。如果您使用的是django 1.4,则必须使用最新版本(),因为它包含一些必要的修复。否则,您必须提供更多有关出错原因的信息。因为图像裁剪是为在管理员中裁剪图像而设计的,所以您实际上不必集成它。只需遵循文档。感谢所有人提出的宝贵建议。。。我已经用django cropper应用程序完成了。