django 備忘

1) django 上傳圖片
class CachedImage(models.Model):
    url = models.CharField(max_length=255, unique=True)
    photo = models.ImageField(upload_to=photo_path, blank=True)

    def cache(self):
        """Store image locally if we have a URL"""

        if self.url and not self.photo:
            result = urllib.urlretrieve(self.url)
            self.photo.save(
                    os.path.basename(self.url),
                    File(open(result[0]))
                    )
            self.save()
http://stackoverflow.com/questions/1308386/programmatically-saving-image-to-django-imagefield
2. 上傳下載大文件
https://djangosnippets.org/snippets/365/
3.API 文檔
https://docs.djangoproject.com/en/1.7/ref/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章