Django AliCloud OSS Storage V2
django-oss-storage-v2 provides a Django AliCloud OSS file storage, compatible with Django 5.1+.
Features
- Django file storage for AliCloud OSS
- Django static file storage for AliCloud OSS
- Works in Python 2 & 3
- Supports Django 5.1+
Installation
$ pip install django-oss-storage-v2
for Django < 5.1
- Add
'django_oss_storage'to yourINSTALLED_APPSsetting - Set your
DEFAULT_FILE_STORAGEsetting to"django_oss_storage.backends.OssMediaStorage" - Set your
STATICFILES_STORAGEsetting to"django_oss_storage.backends.OssStaticStorage" - Configure your AliCloud OSS settings (Refer below).
Storage settings
Use the following settings for file storage.
STATICFILES_STORAGE = 'django_oss_storage.backends.OssStaticStorage'
DEFAULT_FILE_STORAGE = 'django_oss_storage.backends.OssMediaStorage'
Authentication settings
Use the following settings to authenticate with AliCloud OSS.
# AliCloud access key ID
OSS_ACCESS_KEY_ID = <Your Access Key ID>
# AliCloud access key secret
OSS_ACCESS_KEY_SECRET = <Your Access Key Secret>
OSS settings
For public or public-read buckets, storage urls will be bucket_name.endpoint/key format
For private buckets, storage urls will be signed url. The expires time can be set by OSS_EXPIRE_TIME as environment variable or as Django settings. The default value for OSS_EXPIRE_TIME is 30 days.
OSS_EXPIRE_TIME = <Expire Time in Seconds>
# The name of the bucket to store files in
OSS_BUCKET_NAME = <Your bucket name>
# The URL of AliCloud OSS endpoint
# Refer https://www.alibabacloud.com/help/zh/doc-detail/31837.htm for OSS Region & Endpoint
OSS_ENDPOINT = <Your access endpoint>
for Django >= 5.1
- Add
'django_oss_storage'to yourINSTALLED_APPSsetting - Set your
STORAGEsetting as below.
STORAGES = {
"default": {
"BACKEND": "django_oss_storage.backends.OssMediaStorage",
"OPTIONS": {
"access_key_id": <Your Access Key ID>,
"access_key_secret": <Your Access Key Secret>,
"bucket_name": <Your bucket name>,
"endpoint": <Your access endpoint>,
"expire_time": <Expire Time in Seconds>,
}
},
"staticfiles": {
"BACKEND": "django_oss_storage.backends.OssStaticStorage",
"OPTIONS": {
"access_key_id": <Your Access Key ID>,
"access_key_secret": <Your Access Key Secret>,
"bucket_name": <Your bucket name>,
"endpoint": <Your access endpoint>,
"expire_time": <Expire Time in Seconds>,
}
}
}
File storage settings
Use the following settings to configure AliCloud OSS file storage.
# The default location for your project
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# The default location for your media files
# In both cases, your media files will be put into OSS://<your_bucket>/media/
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_ROOT = "/media/"
# Your can use this MEDIA_URL in your django templates
MEDIA_URL = "http://<your-bucket>.<your-endpoint>.aliyuncs.com/media/"
# Or your custom domain MEDIA_URL
MEDIA_URL = "http://<your-custom-domain>/media/"
Staticfiles storage settings
All of the file storage settings are available for the staticfiles storage.
# The default location for your static files
# In both case, your static files will be put into OSS://<your_bucket>/static/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = "/static/"
# Your can use this STATIC_URL in your django templates
STATIC_URL = 'http://<your-bucket>.<your-endpoint>.aliyuncs.com/static/'
# Or your custom domain STATIC_URL
STATIC_URL = "http://<your-custom-domain>/static/"
staticfiles provides command 'collectstatic'. Run following command to collect all sub-folder 'static' of each app and upload to STATIC_URL.
$ python manage.py collectstatic
Testing
First set the required AccessKeyId, AccessKeySecret, endpoint and bucket information for the test through environment variables (Do not use the bucket for the production environment). Take the Linux system for example:
$ export OSS_ACCESS_KEY_ID=<AccessKeyId>
$ export OSS_ACCESS_KEY_SECRET=<AccessKeySecret>
$ export OSS_BUCKET_NAME=<bucket>
$ export OSS_ENDPOINT=<endpoint>
Support and announcements
Downloads and bug tracking can be found at the main project website.
License
- MIT.
Metadata
Release files for django-oss-storage-v2 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-oss-storage-v2-2.0.1.tar.gz | 10.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_oss_storage_v2-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / django-oss-storage-v2-2.0.1.tar.gz
| Download URL | django-oss-storage-v2-2.0.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49a7066ba1969c71e6c7f65962a61f067d7d19804ea3d04ed6074c51513c36cb
|
|
BLAKE2b-256 checksum How to use checksums |
1e34820ab9b17cf903779c02fd97c74cb606260eba1334e699962f2f87935170
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.16
|
Release files / django_oss_storage_v2-2.0.1-py3-none-any.whl
| Download URL | django_oss_storage_v2-2.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d6371318006af5f6f0286177f1c8989e9b20cfe754d08ea6ebdf0de386187ac
|
|
BLAKE2b-256 checksum How to use checksums |
2dd300d3a1a122d733a126c72dcd436f2e1faf295db4d6918ed5d4ef994d161f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.16
|
Security for django-oss-storage-v2 2.0.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.