Need help with CDN on Django App using heroku

9 views
Skip to first unread message

Akash Purandare

unread,
Oct 22, 2018, 3:38:26 PM10/22/18
to Django users
I am trying to serve both static and media files on Heroku by using an S3 bucket, but I do not know how to properly configure the settings.py for the same.
Does anyone know how to do it? If you do, please direct me to the correct set of information.

Andrew Pinkham

unread,
Oct 22, 2018, 3:41:02 PM10/22/18
to django...@googlegroups.com

Michal Petrucha

unread,
Oct 22, 2018, 3:42:37 PM10/22/18
to Django users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Django itself does not ship with built-in support for S3, you'll have
to use a third-party package for that. django-storages appears to be a
popular one, I suggest that you start here:
https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

Good luck,

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJbze/JAAoJEHA7T/IPM/klbT8QAOLnyQUXGiJWWyXk0p1bEDMN
cECp9OkfvZsugvSkubXJF1RppLS9dv4CaPoC2dplC/HjPJeE/4hTtdvZHzHfE/8Y
aFI6ga/grMNvoNFl2F1Khxcau75ZwrJhzWwCQGQDfTnbz4hzjJ9er9asv4IO30X7
+WCGJAg2yLi+GxVEuDM4zC8+7SUzPlVVEL3DsbL6M0UzbcYbWWlZ7laQne3H+BM1
6hQ7nr/u9eYUB3wFVYGbcbtXW1yzSUo/KrW/Xu2Ns3oyhubboDDVr/IsRsRuMwLm
FFkthwS9A2ej37rR1BpQl0ayEOPpsnxNCf3eSytRwfpvxGZkE67kg6qJJdwWaTX+
cteyG8q31LJ2HCpUuFaEUc4YA8D35mGt/4sWfYxXJwDBQ+s4StbhjK3Y/aRYwjdk
oM+ewO/dxm1OQzHWU/a0qcvS8GXAiwIB8AbrsxYwYKPsPqPgx5KDojshuxEH5+X7
kZ7nQZGj7mYRtGkEGjpH/9gaQP6yiVrmORixb6l0vcWLyemmgrC5uIMSfceMpwTH
bUcjyXUfsrOD23ugrv+OKOAYzmce+fHujmEuLe/gy7w4jxWLax+qknf/2MZIcnFV
AXLmRt/hkElTAKnxj8Af+vLtJR20wcrE1rrtt8V4EvxUjKf5yMZgmd7NKw9Bp8Sz
GWuOPu4mWyx1+1sVxzXS
=xJut
-----END PGP SIGNATURE-----

Akash Purandare

unread,
Oct 22, 2018, 3:53:34 PM10/22/18
to Django users
Thank you for the fast reply.

However the issue is not with Whitenoise. Whitenoise can be used to serve static files, yes. But how do I use it to serve media assets in the project?

On Monday, October 22, 2018 at 9:11:02 PM UTC+5:30, Andrew Pinkham wrote:
https://devcenter.heroku.com/articles/django-assets
http://whitenoise.evans.io/en/stable/django.html

Andrew Pinkham

unread,
Oct 22, 2018, 5:05:38 PM10/22/18
to django...@googlegroups.com
On Oct 22, 2018, at 11:53, Akash Purandare <akash...@gmail.com> wrote:
> However the issue is not with Whitenoise. Whitenoise can be used to serve static files, yes. But how do I use it to serve media assets in the project?

Sorry, missed the media part.

Michal is right, you will need to install and configure django-storages for S3.

https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

Related:
https://docs.djangoproject.com/en/2.1/ref/settings/#media-root
https://docs.djangoproject.com/en/2.1/ref/settings/#media-url

This tutorial may be useful (Updated in 2017):

https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/

Andrew
https://jambonsw.com
https://django-unleashed.com

Reply all
Reply to author
Forward
0 new messages