Django Additional topics

Overview

Cloudinary is a cloud-based service that provides an end-to-end image management solution including uploads, storage, administration, image manipulation, and delivery.

Cloudinary's Python library wraps Cloudinary's upload API for easily uploading images and raw files to the cloud. In addition, the Python library simplifies the generation of image manipulation URLs and includes view helper methods for embedding images and transformed images in your web views.

This page includes additional details regarding the integration of Cloudinary with your Django applications.

Configuration options

Setting the configuration parameters can be done either programmatically in each call to a Cloudinary method or globally using an environment variable or the config method.

Your cloud_name account parameter is required to build image URLs. api_key and api_secret are further needed to perform secure API calls to Cloudinary (e.g., image uploads). See API, URLs and access identifiers for more details.

You can find your configuration parameters in the dashboard of our Management Console.

Here's an example of setting configuration parameters globally in your Django application:

cloudinary.config( 
  cloud_name = "sample", 
  api_key = "874837483274837", 
  api_secret = "a676b67565c6767a6767d6767f676fe1" 
)

You can always override the values by passing different values in specific Cloudinary calls.

Another configuration option allows you to dynamically configure the Cloudinary library by defining the CLOUDINARY_URL environment variable. The configuration URL is available in the Management Console's dashboard of your account. When using Cloudinary through a PaaS add-on (e.g., Heroku), this environment variable is automatically defined in your deployment environment. Here's a sample value:

CLOUDINARY_URL=cloudinary://874837483274837:a676b67565c6767a6767d6767f676fe1@sample

In addition to the three mandatory configuration parameters mentioned above, you can define various optional configuration parameters either globally or for each API call specifically. Optional parameters:

  • cdn_subdomain - Boolean (default: False). Whether to automatically build URLs with multiple CDN sub-domains. See this blog post for more details.
  • private_cdn - Boolean (default: False). Should be set to true for Advanced plan's users that have a private CDN distribution.
  • secure_distribution - The domain name of the CDN distribution to use for building HTTPS URLs. Relevant only for Advanced plan's users that have a private CDN distribution.
  • cname - Custom domain name to use for building HTTP URLs. Relevant only for Advanced plan's users that have a private CDN distribution and a custom CNAME.
  • secure - Boolean (default: False). Force HTTPS URLs of images even if embedded in non-secure HTTP pages.

Admin API

While using Cloudinary, all your images are uploaded to the cloud. You can use our Media Library web interface to browse through your uploaded images and generated transformations.

In addition, you can use Cloudinary's administrative API: an intuitive RESTful HTTP API for programmatically managing all of your Cloudinary hosted assets. Main supported operations:

  • Listing all uploaded images and raw files.
  • Receiving details and metadata for uploaded images, including timestamps, format, dimensions, etc.
  • Listing the derived images of uploaded images.
  • Finding all images that share a given tag.
  • Listing all transformations.
  • Listing tags.
  • Receiving transformation details.
  • Creating named transformations.
  • Updating an existing transformation.
  • Deleting images, raw files, derived images and transformations.

For example, the following Python command returns the details of an uploaded image according to its public ID:

import cloudinary.api
cloudinary.api.resource("sample")

# Sample output:  
{ u'bytes': 120264,
  u'created_at': u'2012-07-01T11:10:57Z',
  u'derived': [ 
    { u'bytes': 5729,
      u'format': u'jpg',
      u'id': u'1892cd020611691462a8dc6616f81881',
      u'secure_url': u'https://.../c_fill,w_100,h_100/v1312461204/sample.jpg',
      u'transformation': u'c_fit,h_150,w_100',
      u'url': u'http://.../image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg'},
    { u'bytes': 19173,
      u'format': u'jpg',
      u'id': u'383e22a57167445552a3cdc16f0a0c85',
      u'secure_url': u'https://.../upload/w_230,h_168,c_fit/v1312461204/sample.jpg',
      u'transformation': u'w_230,h_168,c_fit',
      u'url': u'http://.../image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg'}],
  u'format': u'jpg',
  u'height': 576,
  u'next_cursor': u'c87e7b39f7fdd66ec31985196b455c40',
  u'public_id': u'sample',
  u'resource_type': u'image',
  u'secure_url': u'https://.../demo/image/upload/v1371282172/sample.jpg',
  u'type': u'upload',
  u'url': u'http://res.cloudinary.com/demo/image/upload/v1371282172/sample.jpg',
  u'version': 1371282172,
  u'width': 864}

For a general overview and more examples, see this blog post: RESTful API for managing your website's images and other online assets

For more details, see our complete reference of the Admin API.