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
- Template tag - list punctuation for a list of items by shapiromatron 10 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 1 week ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 5 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Why would one need to reinvent the wheel? There is already ReST filter in
markup
contrib library.#
hummm... it's truth, I not knew this :/ thanks :)
#
Please login first before commenting.