Giter Site home page Giter Site logo

django-qiniu-storage's Introduction

Django Qiniu Storage

Build Status

Django storage for 七牛云存储

Install

pip install django-qiniu-storage

Configurations

Django Qiniu Storage 需要以下几个配置才能正常工作。这些配置通过可以环境变量或 settings.py 来设置。环境变量的优先级要高于 settings.py 。

Django Settings / Environment Variable 说明
QINIU_ACCESS_KEY 七牛给开发者分配的 AccessKey
QINIU_SECRET_KEY 七牛给开发者分配的 Secret
QINIU_BUCKET_NAME 用来存放文件的七牛空间(bucket)的名字
QINIU_BUCKET_DOMAIN 七牛空间(bucket)的域名
QINIU_SECURE_URL 是否通过 HTTPS 来访问七牛云存储上的资源(若为'是', 可填True, true 或 1;若为'否', 可填False, false 或 0)

关于 HTTPS域名配置的详情, 可以参考七牛官方文档 如何通过 SSL 的形式来访问七牛云存储上的资源

Usage

如果你对 Django 的 Storage 系统尚不熟悉的话, Django 官方文档中的这几篇: Managing files, Managing static files, The staticfiles app 都是很不错的阅读材料。 建议阅读完后, 再看本教程。

Django Storage System 的应用场景主要有两种: 存放网站用户上传的文件和存放网站自身的js, css, 图片等静态文件:

用例1: 只用七牛托管动态生成的文件(例如用户上传的文件)

在 settings.py 里设置 DEFAULT_FILE_STORAGE :

DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuStorage'

用例2: 用七牛托管动态生成的文件以及站点自身的静态文件(相当于 CDN)

首先,检查你的 INSTALLED_APPS setting, 确保安装了 django.contrib.staticfiles 这个 app。

staticfiles 提供了一个名为 collectstatic 的命令。 它会收集各个 app 的根目录下的 static 子目录下的文件, 并汇总到一个地方。如果将 django settings 里的 STATICFILES_STORAGE 设置为 QiniuStoragecollectstatic 收集到的静态文件就会被统一上传到七牛。

Documentation

It's hosted on the Read The Doc.

Changelog

  • 2.0.0 使用 7.x 版本的 Python SDK。同时支持 Python 2 和 Python 3, 但也因此不再支持 Django 1.4。
  • 新建 ”1.x“ 分支。 今后主分支将使用 7.x 版本的 Python SDK。2.x 会同时支持 Python 2 和 Python 3。
  • 1.2.0 主要是测试方面的改进。利用 Travic CI 对 (Python 2.6, 2.7)×( Django 1.4 -1.7) 的每个组合都跑一遍单元测试。
  • 1.1.0 加上了比较完整的单元测试。Django 1.7 相关的 bug fix.
  • 1.0.1 Bug fix. 使用 6.x 版本的 七牛 Python SDK.

License

基于MIT许可证发布

django-qiniu-storage's People

Contributors

duoduo369 avatar glasslion avatar soloradish avatar zhaozhao avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.