Login

A simple rest template filter

Author:
marinho
Posted:
November 15, 2007
Language:
Python
Version:
.96
Score:
-1 (after 3 ratings)

Attention! This snippet must be ignored, like zgoda pointed with reason: already exists this functionality in markup contrib.

Explanations:

This template filter allows you to render easily a reStructuredText to HTML or another format it supports.

Setup:

Insert the snippet into an_app/templatetags/restutils.py.

Use in template:

{% load restutils %} and use it as following:

  • {{ entry.content|rest:"html" }}
1
2
3
4
5
6
7
8
from django.template import Library
from docutils.core import publish_parts

@register.filter
def rest(value, arg):
    arg = arg or 'html'
    parts = publish_parts(value, writer_name=arg)
    return parts['html_body']

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

zgoda (on November 15, 2007):

Why would one need to reinvent the wheel? There is already ReST filter in markup contrib library.

#

marinho (on November 16, 2007):

hummm... it's truth, I not knew this :/ thanks :)

#

Please login first before commenting.