Skip to content

valericus/django-bunny-storage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-bunny-storage

Provides Bunny.net file storage in Django.

Installation

django-bunny-storage requires Python >= 3.7.

pip install django-bunny-storage

Configuration

Everything is configured in your settings.py file.

Enable application

INSTALLED_APPS = [
    ...
    'django_bunny_storage'
]

Set default storage and credentials

# for Django < 4.2
DEFAULT_FILE_STORAGE = 'django_bunny_storage.storage.BunnyStorage'
BUNNY_USERNAME = 'myusername'
BUNNY_PASSWORD = 'my-random-password-string'
BUNNY_PULL_ZONE = 'https://myzone.b-cdn.net/'  # Optional, defaults to MEDIA_URL
BUNNY_REGION = 'de'  # Optional

# for Django >= 4.2
STORAGES = {
    'default': {
        'BACKEND': 'django_bunny_storage.storage.BunnyStorage',
        'OPTIONS': {
            'username': 'myusername',
            'password': 'my-random-string-password',
            'pull_zone': 'https://myzone.b-cdn.net',  # Optional, defaults to MEDIA_URL
            'region': 'de'  # Optional
        }
    },
}

Username and password can be found under FTP & API Access in your Storage dashboard.

List of available regions can be found here. Or you can see it also under FTP & API Access as two-letter prefix of hostname. Missing prefix is default de region.

You can either set pull zone in storage config or set it to MEDIA_URL, depending on your needs.

Change your media url.

MEDIA_URL = 'https://myzone.b-cdn.net/'

The MEDIA_URL is set based on a linked Pull Zone that you set up in the CDN dashboard. You can use any domain linked to your Pull, either default or custom.

In Templates

Correct MEDIA_URL or pull zone allows you to use the convenience url attribute provided by Django.

<img src="{{ mymodel.file.url }}"/>

Test

Integration tests can be found in tests directory. That's a stub application to run Django tests. The only test tries to upload, download and delete file from storage, so it requires Bunny CDN credentials.

export BUNNY_USERNAME=myusername
export BUNNY_PASSWORD=my-random-string-password
export MEDIA_URL=https://myzone.b-cdn.net/

cd tests
python manage.py test

About

Django Bunny.net storage backend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%