Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-var-cms/llms.txt

Use this file to discover all available pages before exploring further.

django-var-cms provides three complementary media capabilities out of the box: modal previews for any file field in list and detail views, a built-in image cropper with rotate and flip support, and a file conversion API that can transform images, audio, video, and PDF files — all without leaving the control panel.
No configuration is needed. When a model field is an ImageField, the list view renders a thumbnail and clicking it opens a full-size preview modal. When a field is a FileField, an icon link is rendered; clicking it opens the appropriate modal player based on the file extension. The icon and modal type are determined by the file extension using the following map:
ExtensionIconModal behaviour
mp4, webmvideo iconInline <video> player
mp3, wavmusic iconInline <audio> player
pdffile-text iconEmbedded PDF viewer
Any other extensionpaperclip iconOpens/downloads in new tab
You can control the thumbnail dimensions shown in the list view with two attributes on your VarCMSModelAdmin:
class MediaAssetAdmin(VarCMSModelAdmin):
    list_display = ["title", "image", "file"]

    # Thumbnail size in list view (pixels); defaults are 38 × 38
    list_image_width  = 80
    list_image_height = 80

Image Cropper

Every ImageField widget in add/edit forms includes a built-in cropper modal powered by Cropper.js on the frontend and Pillow on the backend. Users can:
  • Draw a custom crop box
  • Rotate the image by arbitrary degrees
  • Flip horizontally and/or vertically
  • Choose an output format (JPEG, PNG, or WebP)
The cropped result is saved to MEDIA_ROOT/crops/ with a 12-character UUID hex filename and its URL is returned to the frontend to update the form field.

Transform Order

When multiple transforms are applied, they are executed in this order:
  1. Flipscale_x = -1 flips horizontally; scale_y = -1 flips vertically
  2. Rotate — rotation is applied with expand=True so the full image is preserved
  3. Crop — the crop box (x, y, w, h) is applied to the transformed image

Crop API Endpoint

POST /var-cms/api/media/crop/
All parameters are sent as multipart/form-data (standard POST body).
ParameterTypeRequiredDescription
file_pathstringRelative media path of the source image (e.g. var_cms/images/2024/06/photo.jpg)
xfloat → intLeft edge of the crop box in pixels
yfloat → intTop edge of the crop box in pixels
wfloat → intWidth of the crop box in pixels
hfloat → intHeight of the crop box in pixels
rotatefloatRotation in degrees (default 0)
scale_xfloat-1 to flip horizontally, 1 for no flip (default 1)
scale_yfloat-1 to flip vertically, 1 for no flip (default 1)
formatstringOutput format: jpeg, png, or webp (defaults to source format)
Success response (200 OK):
{
  "url": "/media/crops/3a7f9c1b2d4e.jpg",
  "path": "crops/3a7f9c1b2d4e.jpg",
  "format": "JPEG",
  "size": [800, 600]
}
The size array reflects the dimensions of the cropped image ([width, height]). JPEG output automatically converts RGBA images to RGB.
The crop endpoint is protected by login_required. Unauthenticated requests are redirected to the login page. Cropped images are saved under MEDIA_ROOT/crops/ and are given a 12-character UUID hex filename to avoid collisions.

Media Conversion API

The conversion endpoint can transform images between formats, convert audio and video files via ffmpeg, and rasterise PDF pages to PNG images via pdf2image.
POST /var-cms/api/media/convert/
ParameterTypeRequiredDescription
file_pathstringRelative media path of the source file
target_fmtstringDesired output extension, e.g. webp, mp3, mp4, png

Supported Conversions

Image-to-image conversion is handled entirely by Pillow — no external binaries required.Supported formats: jpeg / jpg, png, webp, bmp, tiff, gifAny combination of these formats can be converted to any other. Images in RGBA or palette (P) mode are automatically converted to RGB when the target is JPEG. Converted images are saved with quality=90.Success response:
{
  "url": "/media/converted/8c3a1f920b44.webp",
  "path": "converted/8c3a1f920b44.webp",
  "type": "image"
}
Converted files are saved to MEDIA_ROOT/converted/ with 12-character UUID hex filenames.

Requirements

CapabilityRequirementHow to install
Image previews & croppingPillowpip install pillow (included in standard install)
Image format conversionPillowAlready required
Audio / video conversionffmpeg binarysudo apt install ffmpeg
PDF to imagespdf2image + popplerpip install pdf2image + sudo apt install poppler-utils
Pillow is a hard requirement for django-var-cms. Install it alongside the package:
pip install django-var-cms pillow
Without Pillow, the crop endpoint returns a 500 error and image thumbnails will not render.
For PDF support you can use the bundled extra:
pip install django-var-cms[pdf]
This installs pdf2image automatically. You still need poppler-utils as a system package (sudo apt install poppler-utils on Debian/Ubuntu).

Build docs developers (and LLMs) love