Classy solution for file uploads in Django. Inspired by CarrierWave.
Project description
BellHop
BellHop is a simple way to upload files from Django applications. It is inspired by the CarrierWave gem for Ruby. Currently, only AWS is supported.
Installation
Install from PyPI
pip install bellhop
Once done, add the BELLHOP
settings in your settings.py
file:
BELLHOP = {
"STORAGE": "aws",
"AWS_ACCESS_KEY_ID": os.environ["AWS_ACCESS_KEY_ID"],
"AWS_SECRET_ACCESS_KEY": os.environ["AWS_SECRET_ACCESS_KEY"],
"S3_BUCKET": os.environ["S3_BUCKET"],
"S3_REGION": os.environ["S3_REGION"],
}
Example
Define a model in models.py
which would store a file. The model should contain one CharField
which we would use to reference the file.
In this example, the file would be stored using the field file
of model Document
.
class Document(models.Model):
file = models.CharField(max_length=255)
Create a file uploaders.py
in your app. We would register the model with an uploader, where we define the field which references the file as uploadable
, which is file
in our case:
from testapp.models import Document
from bellhop import bellhop, BaseUploader
class DocumentUploader(BaseUploader):
uploadable = "file"
bellhop.register(Document, DocumentUploader)
Now, you can easily upload a file as:
file = open('/path/to/file')
document = Document.objects.create(file=file)
# Access the url of the file
document.file_url
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
File details
Details for the file bellhop-0.0.1.tar.gz
.
File metadata
- Download URL: bellhop-0.0.1.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a1afe9c6d5c8b3dc73cf32375114dcb80f9b882f364ba065408e143b58141d |
|
MD5 | dd79e36b257c4d116534065215834027 |
|
BLAKE2b-256 | 2aa1513db75ebe1f67dded87324d7300aa9cae264dd084d8e83cd3ae08d60ec8 |
File details
Details for the file bellhop-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: bellhop-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e0a709f5e819bc5a8c66bbc7d1b2ca133d8444e809b13411b17c6bfaf6cae6 |
|
MD5 | 75d87da2585c3fc61a26175c9824027b |
|
BLAKE2b-256 | 98a1d4834e29f2119afeb5e18742be3091283bf387b8a3a4f864cf99f20f8939 |