This is the second of a series of articles where I register what I learn about developing Web applications with Pinax.
In the first part I got the sample website running. Now I’m going to add a section for a new application.
I will develop a simple paste bin where people will be able to store small ammounts of text and send it to other people. I will try to write it as a reusable Django application and leverage Pinax’s features.
I will call this application Oxybeles: an implement for throwing things, because when you paste something online you usually want to “throw” it to someone. Besides, a Greek name fits a Pinax app.
Creating a new tab
The first thing I wanted to do was to create a new tab in the site interface for the paste bin app. After searching a little I found out that the website tabs are defined in templates/site_base.html and that the actual text is stored in localizable resource files such as locale/en/LC_MESSAGES/django.po.
So I edited templates/site_base.html and inside the {% block right_tab %} section I inserted this line, among the others:
<td class="tab rtab_pastebin"><div><a href="#">{% trans "Paste Bin" %}</a></div></td>
After that I thought I should edit locale/en/LC_MESSAGES/django.po. But it seemed autogenerated, so I went to learn how that works. Django’s documentation is great. I quickly found out that internationalization is very easy and automatic in Django. While I’m developing I can just use the English text. If I want to update the translation files I can use this command at the project’s root dir:
$ python manage.py makemessages -l en
The first time, I got a message complaining that xgettext was not found. I corrected that by installing gettext:
$ sudo aptitude install gettext
After that, I generated the makemessages command again and I could see that locale/en/LC_MESSAGES/django.po was updated. I learned that I should also compile those files. But I reckon I’d only need to do that before a release, not during development.
So, with only a single new line in a template, I got the Paste Bin tab:
![]()
In the next step I will develop a basic view for this tab and maybe start the model object.
Your feedback is welcome.
[...] Part 2: Creating a new tab. [...]
Pingback by Exploring Pinax Series « Fernando Correia’s Weblog — November 8, 2008 @ 8:33 am
[...] Update 11/14: Fernando Correia did some more digging on how to properly externalize strings in django. [...]
Pingback by Newbie’s Experience Setting Up a Pinax Site « Fitzgerald Steele — November 14, 2008 @ 12:40 pm
Funny foto here
Comment by Tedembeta — December 15, 2008 @ 9:56 pm
Greetings,
Disclaimer: Newbie on Django
Is there a way to do the reverse, e.g., integrate Pinax into an existing django app?
I already have the site 90% ready using django_cms2. I woul like to add wiki, blog and some other functionality on it from pinax, without having to start it over.
If I just include pinax on installed_apps will it work?
Cheers,
CF
Comment by Carlos Franco — October 23, 2009 @ 11:11 am