Skip to main content
Django Qiniu Storage
====================

|Build Status|

Django storage for `七牛云存储 <http://www.qiniu.com/>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

安装
----

::

pip install django-qiniu-storage

配置
----

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
的形式来访问七牛云存储上的资源 <http://kb.qiniu.com/https-support>`__

使用指南
--------

Django Storage 入门
~~~~~~~~~~~~~~~~~~~

Django Storage System 是 Django
框架对文件存储系统做的一层抽象。由于不同的 storage system
使用同样的文件读写接口, Django
应用可以轻松地将其文件存储载体替换为本地文件系统, AWS S3, Openstack,
Azue, Mongodb 或七牛云存储 , 而无需改动应用代码。

如果你对 Django 的 Storage 系统尚不熟悉的话, Django 官方文档中的这几篇:
`Managing
files <https://docs.djangoproject.com/en/1.7/topics/files/>`__,
`Managing static
files <https://docs.djangoproject.com/en/1.7/howto/static-files/>`__,
`The staticfiles
app <https://docs.djangoproject.com/en/1.7/ref/contrib/staticfiles/>`__
都是很不错的阅读材料。
建议阅读完后,了解一些基本的概念和配置项的含义后,再来看本教程接下来的内容。

Django 和 storage 相关的
`settings <https://docs.djangoproject.com/en/dev/ref/settings/>`__
有两项: ``STATICFILES_STORAGE`` 和 ``DEFAULT_FILE_STORAGE``
分别对应\ *网站自身的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`` 设置为
``QiniuStorage``\ ,\ ``collectstatic``
收集到的静态文件就会被统一上传到七牛。

Documentation
-------------

It's hosted on the `Read The
Doc <http://django-qiniu-storage.readthedocs.org/zh_CN/latest/>`__.

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许可证发布

.. |Build Status| image:: https://travis-ci.org/glasslion/django-qiniu-storage.svg?branch=master
:target: https://travis-ci.org/glasslion/django-qiniu-storage


Metadata

Release files for django-qiniu-storage 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-qiniu-storage 2.3.1
File Size Uploaded Provenance Actions
django-qiniu-storage-2.3.1.tar.gz 7.4 kB Without provenance Details for django-qiniu-storage-2.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-qiniu-storage 2.3.1
File Interpreter ABI Platform Actions
django_qiniu_storage-2.3.1-py2-none-any.whl Python 2 none any Details for django_qiniu_storage-2.3.1-py2-none-any.whl

Total release size: 17.6 kB

Release files / django-qiniu-storage-2.3.1.tar.gz

Download URL django-qiniu-storage-2.3.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
26512584058636f24c69599da9770a4c52a508e8e5eb1de275287af4030926fe
BLAKE2b-256 checksum
How to use checksums
bcc0a15b85a9f8bcfb951c0285adffc1cd3028f351216e1ceef957f05d2bffa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_qiniu_storage-2.3.1-py2-none-any.whl

Download URL django_qiniu_storage-2.3.1-py2-none-any.whl
Size 10.1 kB
Tags Python 2
SHA-256 checksum
How to use checksums
30ea73f260dd7597dd57651b0cb541fec7d69afc7e52da1cb67cac424c4f8ef7
BLAKE2b-256 checksum
How to use checksums
cddd737fddfe037935eca77965e6cde5120af440d1579065f891d24cdcf1aae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-qiniu-storage 2.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page