【问题标题】:how to upload image at google cloud storage using app engine in django rest framework?如何使用 django rest 框架中的应用引擎将图像上传到谷歌云存储?
【发布时间】:2020-01-05 16:11:33
【问题描述】:

我已经执行了以下步骤,但是底部的错误一直显示:

install pip install django-google-cloud-storage
add in setting.py file 

DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_BUCKET_NAME = 'is_image_bucket'

发现导入错误 - 没有名为 storages 的模块

我也试过这个教程 https://libraries.io/pypi/django-google-cloud-storage

配置

在您的 django settings.py 文件中,您需要添加以下设置

    GOOGLE_CLOUD_STORAGE_BUCKET = '/your_bucket_name' # the name of the bucket you have created from the google cloud storage console
    GOOGLE_CLOUD_STORAGE_URL = 'http://storage.googleapis.com/bucket' #whatever the ulr for accessing your cloud storgage bucket
    GOOGLE_CLOUD_STORAGE_DEFAULT_CACHE_CONTROL = 'public, max-age: 7200' # default cache control headers for your files
And finally declare the file storage backend you will use on your settings.py file

   DEFAULT_FILE_STORAGE = 'django_google_cloud_storage.GoogleCloudStorage'

ModuleNotFoundError 在 /api/photo_docs/ 没有名为“django_google_cloud_storage”的模块

【问题讨论】:

  • 您能否更清楚地格式化您的问题,并添加您尝试过的内容以及有效/无效的内容,以及任何代码。
  • 您能分享一下您的 settings.py 吗?为了更好的了解,我想你是在关注this tutorial吧?

标签: django python-3.x google-app-engine django-rest-framework


【解决方案1】:

由于您使用的是 Python 3,因此您应该使用 pip3 而不仅仅是 pip。这应该可以解决问题并修复错误。

【讨论】:

    猜你喜欢
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2013-11-30
    • 2015-01-17
    • 2014-10-30
    相关资源
    最近更新 更多