我试图使用s3来存储用户的上传文件,我使用django存储
pip安装django-库
把它添加到我的INSTALLED_APPS
INSTALLED_APPS =( ..。 “仓库”, )
在settings.py中设置变量
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage‘ AWS_ACCESS_KEY_ID = '#################‘ AWS_SECRET_ACCESS_KEY = '#######################‘ AWS_STORAGE_BUCKET_NAME =“我的桶名”
我安装了boto
sudo pip安装boto dyld: DYLD_环境变量被忽略,因为主可执行文件(/usr/bin/sudo)是setuid或setgid 已满足的要求(使用-升级升级):/Library/Python/2.7/site-packages/boto-2.9.0_dev-py2.7.egg中的boto 清理..。
当我保存该项时,django的调试页面跳出,
无法加载Boto的S3绑定。 请参阅https://github.com/boto/boto
有什么想法吗?(我使用mac os x 10.8.3)
发布于 2014-02-03 10:29:25
创建一个bash脚本: install_latest_boto.sh:
#install latest boto from source
cd /home/ubuntu/
sudo mkdir boto_temp
cd boto_temp
sudo git clone git://github.com/boto/boto.git
cd boto
sudo python setup.py install 在django的设置中,django默认存储将是s3:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_S3_FILE_OVERWRITE = False在你的models.py:
class MyBaseModel(models.Model):
class Meta:
abstract = True
@staticmethod
def get_upload_path(instance, filename):
if hasattr(instance, 'get_upload_folder'):
return os.path.join(instance.get_upload_folder(), filename)
else:
raise Exception('Upload Folder is missing')
class User(MyBaseModel):
name = models.CharField(max_length=100)
email = models.EmailField(max_length=255, unique=True)
image = models.ImageField(upload_to=MyBaseModel.get_upload_path, default=None, blank=True, max_length=200)
def get_upload_folder(self):
upload_folder = 'users/images/orig'
return upload_folderhttps://stackoverflow.com/questions/16148100
复制相似问题