Code Monkey home page Code Monkey logo

django-storage-qcloud's Introduction

django-storage-qcloud

Django storage for qcloud's COS

介绍

django-storage-qcloud 是一个服务于腾讯云存储的 Django 自定义存储系统。

安装

  • 使用 pip 安装
pip install django-storage-qcloud

或者直接从 git 安装

pip install git+https://github.com/fordguo/django-storage-qcloud.git
  • 添加 requirements.txt
git+https://github.com/fordguo/django-storage-qcloud.git
  • 配置 setting.py:
    • 将上传文件存放到云 DEFAULT_FILE_STORAGE = 'django_storage_qcloud.storage.QcloudStorage'
    • 将静态文件存放到云 STATICFILES_STORAGE = 'django_storage_qcloud.storage.QcloudStorage'
    • 替换 SecretId, SecretKey, Region, Bucket 的值
    QCLOUD_STORAGE_OPTION = {
        'SecretId': 'SecretId 是开发者拥有的项目身份识别 ID,用以身份认证',
        'SecretKey': 'SecretKey 是开发者拥有的项目身份密钥。',
        'Region': '域名中的地域信息',
        'Bucket': '存储桶是 COS 中用于存储数据的容器,每个对象都存储在一个存储桶中',
    }
    
    • 其他配置:
      • COS_URL = 'https://www.qixincha.com' # 自定义域名, 不配置将使用 COS 默认域名
      • COS_FAST_CDN = False # 默认加速域名是否开启
  • 同步静态文件到云 python manage.py collectstatic

要求

  1. 支持 Python3.4

django-storage-qcloud's People

Contributors

fordguo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-storage-qcloud's Issues

python /app/manage.py collectstatic --noinput --clear 无法执行

执行如下命令:
python /app/manage.py collectstatic --noinput --clear

错误日志如下:
如果不加--clear参数就正常了

Attaching to app-service-new_django_1
django_1        | PostgreSQL is available
django_1        | Traceback (most recent call last):
django_1        |   File "/app/manage.py", line 30, in <module>
django_1        |     execute_from_command_line(sys.argv)
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
django_1        |     utility.execute()
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
django_1        |     self.fetch_command(subcommand).run_from_argv(self.argv)
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
django_1        |     self.execute(*args, **cmd_options)
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
django_1        |     output = self.handle(*args, **options)
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
django_1        |     collected = self.collect()
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 96, in collect
django_1        |     self.clear_dir('')
django_1        |   File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 222, in clear_dir
django_1        |     if not self.storage.exists(path):
django_1        |   File "/usr/local/lib/python3.7/site-packages/django_storage_qcloud/storage.py", line 48, in exists
django_1        |     response = client.object_exists(self.bucket, name)
django_1        |   File "/usr/local/lib/python3.7/site-packages/qcloud_cos/cos_client.py", line 3174, in object_exists
django_1        |     self.head_object(Bucket, Key)
django_1        |   File "/usr/local/lib/python3.7/site-packages/qcloud_cos/cos_client.py", line 538, in head_object
django_1        |     url = self._conf.uri(bucket=Bucket, path=Key)
django_1        |   File "/usr/local/lib/python3.7/site-packages/qcloud_cos/cos_client.py", line 120, in uri
django_1        |     raise CosClientError("Key is required not empty")
django_1        | qcloud_cos.cos_exception.CosClientError: Key is required not empty
django_1        | Sentry is attempting to send 0 pending error messages
django_1        | Waiting up to 2 seconds
django_1        | Press Ctrl-C to quit

media文件无法上传

执行python manage.py collectstatic能将static文件全部上传, 貌似对media中的文件无效. 上传的media文件还是无法上传到cos服务器

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.