Django Storages

1.14.6 · active · verified Thu Apr 09

Django Storages provides a collection of custom storage backends for Django, enabling integration with various cloud storage providers like Amazon S3, Azure Blob Storage, and Google Cloud Storage. It simplifies file management by abstracting away the specifics of each cloud service. The current version is 1.14.6, with active development and regular releases for bug fixes and new features.

Warnings

Install

Imports

Quickstart

To quickly set up `django-storages`, add 'storages' to your `INSTALLED_APPS` and configure `DEFAULT_FILE_STORAGE` to point to your chosen backend. Provide the necessary credentials and bucket names, typically sourced from environment variables for security. This example demonstrates Amazon S3 configuration.

# In your Django project's settings.py

INSTALLED_APPS = [
    # ... your other apps
    'storages',
]

# --- Example for Amazon S3 Backend ---

# Make sure to install boto3: pip install boto3
# Set DEFAULT_FILE_STORAGE for media files
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

# Your AWS settings
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME', '')
AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME', 'us-east-1') # e.g., 'us-east-1'

# Optional: Set a custom domain for your media files if using a CDN
# AWS_S3_CUSTOM_DOMAIN = 'your-cdn-domain.com'

# Optional: Control file access. 'public-read' makes files publicly accessible.
# AWS_DEFAULT_ACL = 'public-read'

# Optional: Don't sign URLs by default (often useful for public access)
# AWS_QUERYSTRING_AUTH = False


# --- Example for Google Cloud Storage Backend (Optional) ---
# Make sure to install google-cloud-storage: pip install google-cloud-storage
# For GCS, you typically provide a path to a service account JSON key file
# or rely on application default credentials.
# GOOGLE_CLOUD_STORAGE_BUCKET_NAME = os.environ.get('GCS_BUCKET_NAME', '')
# GOOGLE_CLOUD_STORAGE_JSON_KEY_FILE = os.environ.get('GCS_JSON_KEY_FILE', '/path/to/your/key.json')

view raw JSON →