Django GridFS Storage Engine
Project description
django-gridfs-storage
Simple django GridFS storage engine
Usage:
-
Install
django_gridfs_storage:pip install django_gridfs_storage -
Into settings.py file of your project, add
gridfs_storagetoINSTALLED_APPS:INSTALLED_APPS = [ ..., 'gridfs_storage', ]
-
add the following variables to your settings:
# defaults to default local mongodb server DEFAULT_GRIDFS_URL = 'mongodb://127.0.0.1:27017' # if set to None, it will refuse to serve files and raise an Exception DEFAULT_GRIDFS_SERVE_URL = None DEFAULT_GRIDFS_COLLECTION = 'storage'
-
To serve files through django (not recommended) you can use this in urls.py:
urlpatterns = [ path('admin/', admin.site.urls), ..., path('media/', include('gridfs_storage.urls')), ]
and set the
DEFAULT_GRIDFS_SERVE_URLto the prefix you specified in the path. in this case its/media/ -
If you wish to use it on all
FileFieldandImageFieldset it as the default Storage:DEFAULT_FILE_STORAGE = 'gridfs_storage.storage.GridFSStorage'
-
If you wish to use on individual field bases set it as the field storage:
from django.db import models from gridfs_storage.storage import GridFSStorage class SampleModel(models.Model): attachment = models.FileField(storage=GridFSStorage()) first_pic = models.ImageField(storage=GridFSStorage(location='sample/images')) # To store in a different collection than "storage" another_pic = models.ImageField(storage=GridFSStorage(collection='image_storage')) # Serve through custom cdn connected to the same gridfs or similar, the limit is the sky :) served_outside = models.ImageField(storage=GridFSStorage(base_url='https://img.cdn/serve/'))
Requirements:
- Python 3.6 or higher.
- Django 2.2 or higher.
- MongoDB 3.4 or higher.
Tests? None.
We crash production like real men
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-gridfs-storage-0.0.2.tar.gz.
File metadata
- Download URL: django-gridfs-storage-0.0.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac4b2ff52aa6c0b03d42cfb98492283f10e88b70f0ea6df03bd94f79c44da038
|
|
| MD5 |
c8212b7d1a41b135b95d4ec0f6480058
|
|
| BLAKE2b-256 |
88bfe515ea4112a3d884a67a022076a6de39435539c90925cea3d9f2e555afcf
|
File details
Details for the file django_gridfs_storage-0.0.2-py3-none-any.whl.
File metadata
- Download URL: django_gridfs_storage-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
444c686970466ca445a3c28f35ec1c5ffc8c52a74d632ee41778bbef4afe5041
|
|
| MD5 |
5317901f9b7863664ee15f5875e57803
|
|
| BLAKE2b-256 |
05115f83060c13f8f4ff9f475aff2a923b9d7457665038f94845e8d45b9c7266
|