This package provides Bunny.net file storage for Django. An improved and working version. Thanks to Will Meyers' django-bunny-storage.
python-bunnycdn-storage
requires Python >= 3.7 and Django >= 3.0
pip install python-bunnycdn-storage
Details to configure Bunny.net Storage.
To use:
- Add
bunnycdn_storage
to yourINSTALLED_APPS
insettings.py
file
INSTALLED_APPS = [
...
'bunnycdn_storage',
...
]
- Add
BUNNY_USERNAME
andBUNNY_PASSWORD
to your settings.
BUNNY_USERNAME = 'your_bunny_username'
BUNNY_PASSWORD = 'your_bunny_password'
# This is optional
BUNNY_REGION = 'de'
The above settings must match the storage zone and password of your Bunny.net account. To find Storage zone Username and Password, open the FTP & API Access under Storage in your Bunny.net dashboard.
Note: You must include BUNNY_REGION
if you choose another region other than the default Falkenstein region, DE.
- Change the MEDIA_URL in
settings.py
file.
MEDIA_URL = 'https://your_zone.b-cdn.net/' # This is your Pull Zone linked hostname
The MEDIA_URL
corresponds to the linked Pull Zone you setup in the Bunny.net dashboard.
- Change the default file storage in
settings.py
file.
DEFAULT_FILE_STORAGE = 'bunnycdn_storage.storage.BunnyCDNStorage'
This setup uses media url context processor to serve media. Refer to the documentation in Django for more details.
- Add
django.template.context_processors.media
in thecontext_processors
option of TEMPLATES insettings.py
file.
...
'django.template.context_processors.media',
...
To load media properly without getting 404, use:
<img src="{{ MEDIA_URL }}{{ your_model.file }}" />
That's it.