配置 Django 和谷歌云存储? [英] Configure Django and Google Cloud Storage?

查看:21
本文介绍了配置 Django 和谷歌云存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Appengine.

I am not using Appengine.

我有一个在 VM 上运行的普通 Django 应用程序.我想使用 Google Cloud Storage 来提供我的静态文件,以及上传/提供我的媒体文件.

I have a plain vanilla Django application running on a VM. I want to use Google Cloud Storage for serving my staticfiles, and also for uploading/serving my media files.

我有一个桶.

如何将我的 Django 应用程序链接到我的存储桶?我试过 django-storages.这可能有效,但我必须做些什么来准备我的存储桶以供我的 django 应用程序使用?在我的 Django 设置中我需要什么基线配置?

How do I link my Django application to my bucket? I've tried django-storages. That may work, but what do I have to do to prepare my bucket to be used by my django application? And what baseline configuration do I need in my Django settings?

当前设置:

# Google Cloud Storage
# http://django-storages.readthedocs.org/en/latest/backends/apache_libcloud.html
LIBCLOUD_PROVIDERS = {
    'google': {
        'type'  : 'libcloud.storage.types.Provider.GOOGLE_STORAGE',
        'user'  : <I have no idea>,
        'key'   : <ditto above>,
        'bucket': <my bucket name>,
    }
}

DEFAULT_LIBCLOUD_PROVIDER = 'google'
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'
STATICFILES_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'

推荐答案

Django-storages 有一个谷歌云存储的后端,但它没有记录,我意识到在 repo 中查找.可以使用此设置:

Django-storages has a backend for Google Cloud Storage, but it is not documented, I realised looking in the repo. Got it working with this setup:

DEFAULT_FILE_STORAGE = 'storages.backends.gs.GSBotoStorage'
GS_ACCESS_KEY_ID = 'YourID'
GS_SECRET_ACCESS_KEY = 'YourKEY'
GS_BUCKET_NAME = 'YourBucket'
STATICFILES_STORAGE = 'storages.backends.gs.GSBotoStorage'

要获取 YourKEY 和 YourID,您应该在设置选项卡中创建 Interoperability 键.

To get YourKEY and YourID you should create Interoperability keys, in the settings tab.

希望它有所帮助,您不必费力地学习它:)

Hope it helps and you don't have to learn it the hard way :)

如果你还没有的话,依赖项是:

Ah in case you haven't yet, the dependencies are:

pip install django-storages
pip install boto

这篇关于配置 Django 和谷歌云存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆