This is the third of a series of articles about my experience with the Pinax project. I am building a sample paste bin application named Oxybeles, of all things.

On the previous articles I installed Pinax and created a tab in the main menu for my new app. Now I want to create a basic view, but first I need to start a new Django app.

$ python manage.py startapp oxybeles

It seems that it would be appropriate to move it into the apps directory, so I did that:

$ mv oxybeles/ apps/

Here, I took a detour to create a GitHub repository to host this application, but I won’t record my git sessions on this series, because the focus is on Pinax and Django.

After exploring a bit how other Pinax application URLs are set up, I decided to start by copying the pattern used in the “about” application.

I started by creating a basic template:

$ mkdir templates/oxybeles $ gedit templates/oxybeles/new.html

I created the new file templates/oxybeles/new.html with this content:

{% extends "site_base.html" %} {% load i18n %} {% block head_title %}{% trans "Paste Bin" %}{% endblock %} {% block body %} {% blocktrans %} <p>This will be a form to post some text.</p> {% endblocktrans %} {% endblock %}

Next, I created a new urls.py file inside the new app:

$ gedit apps/oxybeles/urls.py

from django.conf.urls.defaults import * from django.views.generic.simple import direct_to_template urlpatterns = patterns('', url(r'^$', direct_to_template, {"template": "oxybeles/new.html"}, name="oxybeles_new"), )

Then I added the new application to the main urls.py file:

$ gedit urls.py

Around line 56, inside the urlpatterns list declaration, I inserted:

(r'^pastebin/', include('oxybeles.urls')),

And finally, I changed the menu option to link to the new URL:

$ gedit templates/site_base.html

Changing:

<td class="tab rtab_pastebin"><div><a href="#">{% trans "Paste Bin" %}</a></div></td>

To:

<td class="tab rtab_pastebin"><div><a href="{% url oxybeles_new %}">{% trans "Paste Bin" %}</a></div></td>

Now the Paste Bin menu item links to http://127.0.0.1:8000/pastebin/ and that renders the oxybeles/new.html template that shows just:

This will be a form to post some text.

Good, the new app is linked to Pinax and the basic view is working. In the next article I’ll try to get a basic form working.

The application source code at this stage can be found in GitHub.