Cloudinary provides a cloud-based image and video management services. It enables users to upload, store, manage, manipulate, and deliver images and video for websites and apps.
the reason why i'm using cloudinary is because, i onced deployed my django project on heroku and the images i uploaded on the admin did not reflect on the user front page.
I found a solution. CLOUDINARY
The way i think it works with cloudinary is that
once you select the image. it get's uploaded to cloudinary and you can acccess it from there and render them to your template
Let's go into it
make sure your virtual environment is working. Run this code to install cloudinary to your virtual environment
pip install cloudinary
open your settings.py file and paste this code
import cloudinary
import cloudinary.uploader
import cloudinary.api
paste this code in your setting.py file
cloudinary.config(
cloud_name = "your heroku cloud name",
api_key = "your heroku api key",
api_secret = "your heroku secret key"
)
In the model where you wish to use image. do this
from cloudinary.models import CloudinaryField
and add the image to the table you wish to use upload image option
class Listing(models.Model):
realtor = models.ForeignKey(Realtors, on_delete=models.DO_NOTHING)
title = models.CharField(max_length=200)
address = models.CharField(max_length=200)
photo_main = CloudinaryField('image')
your views will look this
def Listings(request):
all_data = Listing.objects.all()
context = {'listing': paged_listings}
return render(request, 'listings/listings.html', context)
note. this's only when you want to deploy your project to heroku