restructured text on django
Using markup makes it less painful to enter texts in web. Django includes three markup filters to use: textile, markdown, and reST (restructured text). I use reST a lot because it has lots of features that I couldn't live without (like toc directive) and because it has the blessing of python.
reST on Django
Installation of docutils on Linux
To be able to use reST, install docutils on your server. On Debian based Linux:shell>sudo apt-get install python-docutils
Installing docutils on Dreamhost
On Dreamhost, it is more complicated since users don't have root access. Ssh into dreamhost. In Windows, use Putty. In Linux, go into shell. My server resides in compton, so I ssh into compton.dreamhost.com. Your account may reside on different servers, so don't use 'compton' unless that is the name of your server.local>ssh myaccount@compton.dreamhost.comDownload the latest docutils source code
host>wget http://docutils.sf.net/docutils-snapshot.tgzUnpack
host> tar zxvf docutils-snapshot.tgz host> cd docutils-snapshot.tgzInstall it to a local directory
host> ./setup.py install --prefix=~/tmpCopy or move the built docutils package into the same path as PYTHONPATH. If you are using the same path as the one given in the dreamhost's wiki instruction, pythonpath will be ~/django_source/. Also I'm using python2.4 but dreamhost has python 2.3 by default. If you're running 2.3, path may not be the same.
host> mv ~/tmp/lib/python2.4/site-packages/docutils \ ~/django_source host> pkill python
Add "django.contrib.markup" in your INSTALLED_APPS in settings.py
# it looks like this in my settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'greenmachine.base',
'greenmachine.module.document',
'greenmachine.module.registration',
'django.contrib.markup',
)
Use filter in template
In template, add "{% load markup %}" in the beginning. Use appropriate filter. ... {{ myText|textile }}... {{ myText|restructuredtext}}
... {{ myText|markdown}}
My document template looks like this:
{% extends "index.html" %}
{% load markup %}
{% block content %}
Title: {{object.title}}
Description:
{{object.description|restructuredtext}}
{% endblock %}
Input text
Benefits of Django ======================== * runs on python * fast development * fast execution * free and open-source * lots of commercial success Django requirement ======================== * mod_python or fcgi capable web server * python 2.3 or above * optional libraries: PIL, docutils, MySQLdb
Result
Benefits of Django
- runs on python
- fast development
- fast execution
- free and open-source
- lots of commercial success
Django requirement
- mod_python or fcgi capable web server
- python 2.3 or above
- optional libraries: PIL, docutils, MySQLdb
