Provides a Django storage implementation that uses a single database table.
Project description
This Python package provides a Django storage implementation that uses a single database table.
Django developers may find this package may be most helpful for use in their test and prototype environments. This package may also be useful in launching small-scale projects/environments quickly without needing additional infrastructure setup.
WARNING: For production applications, please consider using a CDN instead of this package, as it is not a good practice to serve files from a database. Website performance will suffer! Please see the section "Alternatives" below for performant and scalable storage options.
Features / Benefits
- Easy to install and configure.
- Serve files properly when there are multiple django servers under a load balancer.
- Files persist in database when application server is rebuilt (as long as database is not hosted on the application server).
- In unit testing scenarios, created files can be automatically "rolled back" out of existence if the unit test uses a transaction, which is how
django.test.TestCase
works.
Installation
pip install django-single-table-db-storage
Setup
In your django settings file, add 'django_single_table_db_storage'
to INSTALLED_APPS
.
INSTALLED_APPS = [
...
'django_single_table_db_storage',
...
]
Also in your django settings file, set up the default storage. It is recommended that you add a TODO to remind yourself to use a better storage in the future.
# TODO: As this project scales, a CDN or S3-compatible storage for production
# might be a better solution.
DEFAULT_FILE_STORAGE = 'django_single_table_db_storage.storage.SingleTableDbFileStorage'
Mount the URLs where you want in your urls.py
file.
urlpatterns = [
...
path('files/', include('django_single_table_db_storage.urls')),
....
]
Run the database migrations to create the table.
./manage.py migrate
...And now your environment is set to use the file storage.
Alternatives
You can find other file storage alternatives for Django here:
https://djangopackages.org/grids/g/storage-backends/
This package contains a similar and possibly better implementation to this library, depending on your use case and license that you prefer:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-single-table-db-storage-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdefcb08bc11749baaccf99c62eee40a49e39fb370c85b9d30ab4056624bbe3a |
|
MD5 | 4644245cdb89f9f30ec8ed23585822b6 |
|
BLAKE2b-256 | a02158ebd5a4e6ee62d1a39ada1d9fd055d00e9071af3949c8a80e0ab5a676d8 |
Hashes for django_single_table_db_storage-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4954e3ffb20c99e0f34576339e227998f884731b5e976715001d40b28917f5b |
|
MD5 | 8130f400b87b9da6518f3fa749025884 |
|
BLAKE2b-256 | a424ee0b77eb29b4e2eaeb672e48787ee3664dd59505f6d322a54552100e76ca |