Templated-docs: office documents for Django

Templated-docs is a Django package that allows you to generate documents, including texts, spreadsheets and presentations, from templates. It utilises LibreOffice as an underlying conversion document mechanism.


  • Generate any LibreOffice-supported document from within Django.
  • Use Django template language inside office documents.
  • Create custom generation management commands to integrate with other systems.


To install templated-docs:

  1. Make sure you have LibreOffice >= 4.3.0 installed on the same machine
  2. Install a package with pip install templated-docs
  3. Add templated_docs to INSTALLED_APPS

If you are using cpython you may need the libffi development package in order to compile this module’s dependencies.

  • Ubuntu: apt-get install libffi-dev
  • MacOS: brew install libffi


To generate a document from a template sample.odt you can write a view like this:

from templated_docs import fill_template
from templated_docs.http import FileResponse

def get_document(request):
  A view to get a document filled with context variables.
  context = {'user': request.user, 'foo': 'bar'}
  filename = fill_template('sample.odt', context, output_format='pdf')
  visible_filename = 'greeting.pdf'
  return FileResponse(filename, visible_filename)
templated_docs.fill_template(template_name, context, output_format='odt')
Fill a template template_name using a context dictionary as a context, optionally converting it to the output_format. Returns a filename of a generated file.