lck.django 0.8.5 documentation

This Page


Various unrelated routines and helper classes.

Rendering functions

redirect(request[, link, override_request]) → HttpResponseRedirect

A smarter redirect which takes the redirection target from a given param. The lookup for the redirection target is as follows:

  • ‘redirect_to’ in GET or POST (in that order)
  • ‘next’ in GET or POST (in that order)
  • the link fallback argument (‘/’ if not given)

If override_request is True, link is always followed.

render(request, template_name, context[, debug, mimetype]) → HttpResponse

Renders the context within for a request using a template named template_name returning the required mimetype.

render_json(obj) → HttpResponse

Dumps the object in the obj param to a JSON string and returns it via HTTP using the application/json mimetype.

typical_handler(request, form_class, template, initial={}, initial_kwargs={}, context={}, redirect_on_success=None)

A handler for a typical form workflow:

  1. Initialize a form object.
    1. if there are POSTed data and/or files, use them
    2. otherwise use initial as initial data and initial_kwargs as keyword arguments for the form object constructor.
  2. If the form validates, save it and either: override the template name with a version using the “_complete.html” suffix. or: redirect using the redirect_on_success arguments
  3. If there are errors on the form, prepare an additional error_summary string on the form object (for consumption by the template).
  4. Render the result.



Like commit_on_success, but doesn’t commit existing transactions.

This decorator is used to run a function within the scope of a database transaction, committing the transaction on success and rolling it back if an exception occurs.

Unlike the standard transaction.commit_on_success decorator, this version first checks whether a transaction is already active. If so then it doesn’t perform any commits or rollbacks, leaving that up to whoever is managing the active transaction.

Taken from:


cut(text, length=40, trailing=u' (...)')

Cuts text to a predefined length and appends a trailing ellipsis for longer sources.


alias of chain


The legacy lazy_chain name will be removed in lck.django 1.0. Use dj.chain.


If the remote address in request is a localhost, check for X_FORWADED_FOR. Which addresses are considered local is defined by the INTERNAL_IPS list in, by default these are, ::1 and “localhost”.