Jump to >


class DiffRenderer(diff_file, chunk_index=None, highlighting=False, collapse_all=True, lines_of_context=None, extra_context=None, allow_caching=True, template_name='diffviewer/diff_file_fragment.html', show_deleted=False)[source]

Renders a file’s diffs.

A DiffRenderer is constructed as needed and set up for render, and then thrown away. The rendered diff can show that of a whole file (in a collapsed or fully expanded state), or a particular chunk within a file.

The rendered diff will be optimistically pulled out of cache, if it exists. Otherwise, a new one will be rendered and placed in the cache.

The diff_file (from get_diff_files) is the only required parameter. The renderer may modify the contents of this, and should make a copy if it needs to be left untouched.

Note that any of the render functions are meant to be called only once per DiffRenderer. It will alter the state of the renderer, possibly disrupting future render calls.


Renders the diff to an HttpResponse.


Returns the diff as a string.

The resulting diff may optimistically be pulled from the cache, if not rendering a custom line range. This makes diff rendering very quick.

If operating with a cache, and the diff doesn’t exist in the cache, it will be stored after render.


Renders a diff to a string without caching.

This is a potentially expensive operation, and so is meant to be called only as often as necessary. render_to_string will call this if it’s not already in the cache.


Creates and returns a cache key representing the diff to render.


Creates and returns context for a diff render.


Returns the DiffRenderer class used for rendering diffs.


Sets the DiffRenderer class used for rendering diffs.

get_diff_renderer(*args, **kwargs)[source]

Returns a DiffRenderer instance used for rendering diffs.