How to store and serve static images using Django, Pythonanywhere, CDN and cloud storage

313 views Asked by At

I'm quite new to web development, just a self-taught enthusiast, so be kind :)

Right now I'm trying to deploy my website (built with Django) on Pythonanywhere. Following all advice on static files and it actually works. So basics are done. But images load painfully slow. I know there is some size and weight optimisation to do, but I also heard that the best way to serve large amount of images is to store them separately from the code (in Amazon S3, Google Cloud Storage) and serve through CDN. I have also found a nice service called IMGIX to always serve the most appropriate version of an image.

Now the hard question: how does it work together? OK, I can upload all images to the bucket, point CDN to it too. But then how do I go about 'collectstatic' in Django? How do I keep those images linked to the models? Do I resolve it by pointing STATIC_DIR and STATIC_ROOT to that bucket? My mind is failing me here and googling did not help either.

Any help would be highly appreciated.

0

There are 0 answers