Uploading Images to Cloudinary

pip install cloudinary

settings.py

import cloudinary
import cloudinary.uploader
import cloudinary.api
INSTALLED_APPS = [
    'cloudinary'
    ]

Configuration Cloudinary account

Add the configuration credentials in settings.py as shown below:


# adding config
cloudinary.config( 
  cloud_name = "YOUR_CLOUD_NAME", 
  api_key = "YOUR_API_KEY", 
  api_secret = "YOUR_API_SECRET" 
)

models.py

from django.db import models
from cloudinary.models import CloudinaryField

class photos(models.Model):
    # title field
    title = models.CharField(max_length=100)
    #image field
    image = CloudinaryField('image')

Now When Save model image store in cloude

How To Show Html Template

same way to default django template

        <!-- loop through all the images -->
        {% for pic in photo %}
        <h2>{{pic.title}}</h2>
            <img src="{{pic.image.url}}" alt="fish">
        {% endfor %}

Last updated