How to use Cloudinary with Django Application for uploading Images.

Why not to use Django for serving Static files in Production?

Django is not as fast or efficient while serving static files, most of the larger web applications use dedicated server or services like AWS S3 / Cloudinary for serving static file which helps in loading these files much faster.

In this post we are using Cloudinary for serving static files to our web application so lets get started.

Lets say you need to upload images to the server so in your models.py file nothing different to do over there its the same way you do it all the time.

image = models.ImageField(upload_to='Portfolio/', null=True)

Therefore, to use cloudinary in your application first, you will need to install the cloudinary package using the following command.

pip install cloudinary dj3-cloudinary-storage

Now let us add some settings and connect our application to cloudinary.

Open your settings.py file and add cloudinary in your installed apps section

INSTALLED_APPS = [ ...
'cloudinary',
]

Now, at the bottom of your settings.py add your Cloudinary identifiers as below that you will get after signing up on Cloudinary.

CLOUDINARY_STORAGE = {'CLOUD_NAME': 'Your Cloud Name','API_KEY': 'Your API KEY','API_SECRET': 'Your Secret Key',}DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'

Thats all you have successfully connected your application with cloudinary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store