gpt4 book ai didi

django - 无法加载 Boto 的 S3 绑定(bind)。 (安装博托)

转载 作者:行者123 更新时间:2023-12-03 17:53:05 24 4
gpt4 key购买 nike

我正在尝试使用 s3 来存储用户的上传文件,我使用 django 存储

pip install django-storages


将其添加到我的 INSTALLED_APPS

INSTALLED_APPS = (

...

'storages',

)


在 settings.py 中设置变量

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_ACCESS_KEY_ID = '#################'

AWS_SECRET_ACCESS_KEY = '#######################'

AWS_STORAGE_BUCKET_NAME = 'mybucketname'


我已经安装了boto

sudo pip install boto

dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

Requirement already satisfied (use --upgrade to upgrade): boto in /Library/Python/2.7/site-packages/boto-2.9.0_dev-py2.7.egg

Cleaning up...


当我保存项目时,django的调试页面跳出来,

Could not load Boto's S3 bindings.

See https://github.com/boto/boto


有任何想法吗? (我使用 mac os x 10.8.3)

最佳答案

创建一个 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_folder

关于django - 无法加载 Boto 的 S3 绑定(bind)。 (安装博托),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16148100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com