django-private-storage

raw JSON →
3.1.3 verified Fri May 01 auth: no python

Provides private media file storage for Django projects, allowing files to be served only to authenticated users with permission checks. Version 3.1.3 is current. Release cadence is irregular.

pip install django-private-storage
error django.core.exceptions.ImproperlyConfigured: PRIVATE_STORAGE_ROOT is not set.
cause Missing PRIVATE_STORAGE_ROOT setting.
fix
Add PRIVATE_STORAGE_ROOT = '/path/to/storage/' to your Django settings.
error AttributeError: module 'private_storage.storage' has no attribute 'PrivateStorage'
cause Wrong import path in version 3.
fix
Use from private_storage.storage.filesystem import PrivateStorage.
gotcha The default auth function is `allow_staff` (only staff users). If you want all authenticated users, set `PRIVATE_STORAGE_AUTH_FUNCTION = 'private_storage.permissions.allow_authenticated'`.
fix Set the auth function explicitly in Django settings.
gotcha PrivateStorage does not work with the default Django file storage; it requires a custom storage backend. Do not use `DefaultStorage` or `FileSystemStorage` for private files.
fix Use `from private_storage.storage.filesystem import PrivateStorage` as the storage class.
deprecated Before version 3, the import path was `from private_storage.storage import PrivateStorage`. In v3, the storage classes moved to submodules.
fix Use `from private_storage.storage.filesystem import PrivateStorage`.

Add to INSTALLED_APPS, configure root and auth function, then use PrivateStorage as the storage backend.

INSTALLED_APPS = [
    'private_storage',
    ...
]

PRIVATE_STORAGE_ROOT = '/path/to/private/media/'
PRIVATE_STORAGE_AUTH_FUNCTION = 'private_storage.permissions.allow_authenticated'

from private_storage.storage.filesystem import PrivateStorage
private_storage = PrivateStorage()