ReStructuredText in Django

16 May 2008

dbr left a comment on this site:

I concur with the other two comments - this is one of the nicer blog'y site layouts I've seen. The comment system is also actually pleasant to use, unlike every single other one I've (not)-used \o/

dbr (May 16, 2008)

Thanks for the compliment. I have talked before about my philosophy towards forms:

I do not make want to make it like Indiana Jones and the Last Crusade just to make a comment: roll under a flying saw, spell something in Hebrew and then take a flying leap into the abyss. Furthermore moderation of spam is my problem, not yours.

—Zeth on comment-spam (3 July 2007)

dbr continues:

One slight bug, you need to enter two backslashes to make it visible.

dbr (May 16, 2008)

That is not a bug that is a feature! That is the escaping mechanism of ReStructuredText (as well as Python and lots of other languages). The comments form does not allow HTML but it allows ReStructuredText, as I explain below.

Ryan also left a comment:

For your blog post model, what did you do for entering posts? Do you still use the default admin interface, or did you make your own views for posting and whatnot? I haven't looked into it much, but does Django automatically include much in the way of wysiwyg text editors for text fields?

Ryan (May 15, 2008)

Answering your questions in reverse order:

  • Wysiwyg text editors

There is no default Django WYSIWYG text field, but some people use Javascript components such as TinyMCE which slots in nicely (instructions).

  • Default admin interface vs own views

I have the admin interface as one way to enter posts, but I also made a simple command-line tool for entering posts, I also made some scripts for importing all my old posts from Pyblosxom.

I did create one admin view, I overrode the 'delete comment' view to create a button that adds the IP addresses of deleted spam comments to a block list.

At some point I will make a 'Preview' view and button. At the moment I can save posts as drafts but not view drafts in the site template before it goes live.

  • What did you do for entering posts?

I write a new post in a real text editor such as Emacs or gedit in ReStructuredText format, which I can then either paste into the admin interface, or use my little script to squirt them into Django.

Markup in Django

'contrib' forms the 'standard library' of Django. One of these packages is called "markup". It provides filters for three markup languages: ReStructured Text, Markdown and Textile.

I chose to use ReStructured Text because using that to write my new posts because I like the format and getting confident with ReStructured Text will be useful in lots of other contexts also.

To use it in Django, just add django.contrib.markup to the INSTALLED_APPS list in settings.py. In a template, you can load it and use it like this:

{% load markup %}
{{ comment.comment|restructuredtext }}

In the next post I will explain how to write in ReStructured Text,

What do you have to say?

Show Editing Help


About

Hello, my name is Zeth, I'll be your host here.

Command Line Warriors is about taking control of your own technology, it looks at our experiences of computing; especially using GNU/Linux, the Python programming language, the command-line and issues such as techno-ethics, best practices and whatever is cool now. If you take control of your technology then you are a Warrior too!

This site is your site too which means that you can contribute and get involved. You can leave comments using the facility provided. For me, the comments and discussions are by far the best part of the site. So please do have your say!

Latest Discussions

Kurushiyama

June 30, 2008
XML is no replacement for SGML, it's a subset.
An Introduction to ReStructuredText

Peter

June 27, 2008
This is pretty nice, maybe if an mget or mput could be added it would really improve its use. not sure how to do that couldn't figure it out using ...
SFTP in Python: Really Simple SSH

Bryce

June 25, 2008
Sorry to comment on an older post, but I wanted to point out that you misunderstand the purpose of at least two of the extensions you mentioned: Foxmarks and Greasemonkey. ...
Will Epiphany be able to compete with Firefox's extensions?

The Dude

June 24, 2008
1. Green Eggs 2. Ham 3. *things* .. _Here: http://google.com/
An Introduction to ReStructuredText

S.

June 20, 2008
A space is .25 of a level??? Instead of tabs or spaces, or tabs being so many spaces, there should be a "level" character, where one character equals one level ...
Twelve commandments for Beautiful Python code

jk

June 20, 2008
First, excuse my english. I was using firefox like every body else, until one day i look on Top command utility (system monitor) that firefox was using 190Mb of my ...
Epiphany and Webkit 2008

Tom

June 17, 2008
find -exec is nice, but escaping can become complicated if you want to execute, say, awk using a weird pattern. My preferred way is not elegant at all but very ...
Five Tips for Easter

Casual reader...

June 16, 2008
"Firstly, sending your friend a 6 MB file over the network, is nothing like murder. " It is true that sending your friend a file over the network is nothing ...
Filesharing is the democratic choice

Adam Bielinski

June 15, 2008
I like using epiphany because it's fast and lightweight, and is more intuitive in a GNOME environment. I don't think extensions are everything.
Will Epiphany be able to compete with Firefox's extensions?

Kewlmyst

June 12, 2008
Hmmm ... I have been rsync for a long time just to do back ups, but be aware that if you put the --delete option, and have a nice cron ...
Backing up my laptop

yegle

June 12, 2008
@Zeth Hello Zeth,can you share your script you mentioned about the Six degrees of separation?I'm so intrested about it~ And, this is really an excellent work !Thank you for shareing ...
Twitter and GNOME integration

Orlandus

June 9, 2008
Well, if they offer only an object-code-only license.and no object code, then I suppose nobody is legally entitled to have the software at all.
Are your Firefox extensions proprietary software?

Swashbuckler

June 5, 2008
"object code is a C term." Uh no. It's any compiled language.
Are your Firefox extensions proprietary software?

Craig

June 4, 2008
Here's a thought: I don't recall ever being asked to agree to a EULA before downloading a Firefox add-on. Maybe I just haven't downloaded any proprietary ones, but I think ...
Are your Firefox extensions proprietary software?