Getting started with philo

Note

This guide assumes that you have worked with Django’s built-in administrative interface.

Once you’ve installed philo and mptt to your python path, there are only a few things that you need to do to get philo working.

  1. Add philo and mptt to settings.INSTALLED_APPS:

    INSTALLED_APPS = (
            ...
            'philo',
            'mptt',
            ...
    )
  2. Syncdb or run migrations to set up your database.

  3. Add philo.middleware.RequestNodeMiddleware to settings.MIDDLEWARE_CLASSES:

    MIDDLEWARE_CLASSES = (
            ...
            'philo.middleware.RequestNodeMiddleware',
            ...
    )
  4. Include philo.urls somewhere in your urls.py file. For example:

    from django.conf.urls.defaults import patterns, include, url
    urlpatterns = patterns('',
            url(r'^', include('philo.urls')),
    )
    

Philo should be ready to go! (Almost.)

Hello world

Now that you’ve got everything configured, it’s time to set up your first page! Easy peasy. Open up the admin and add a new Template. Call it “Hello World Template”. The code can be something like this:

<html>
        <head>
                <title>Hello world!</title>
        </head>
        <body>
                <p>Hello world!</p>
                <p>The time is {% now %}.</p>
        </body>
</html>

Next, add a philo Page - let’s call it “Hello World Page” and use the template you just made.

Now make a philo Node. Give it the slug hello-world. Set the view_content_type to “Page” and the view_object_id to the id of the page that you just made - probably 1. If you navigate to /hello-world, you will see the results of rendering the page!

Setting the root node

So what’s at /? If you try to load it, you’ll get a 404 error. This is because there’s no Node located there - and since Node.slug is a required field, getting a node there is not as simple as leaving the slug blank.

In philo, the node that is displayed at / is called the “root node” of the current Site. To represent this idea cleanly in the database, philo adds a ForeignKey to Node to the django.contrib.sites.models.Site model.

Since there’s only one Node in your Site, we probably want hello-world to be the root node. All you have to do is edit the current Site and set its root node to hello-world. Now you can see the page rendered at /!

Editing page contents

Great! We’ve got a page that says “Hello World”. But what if we want it to say something else? Should we really have to edit the Template to change the content of the Page? And what if we want to share the Template but have different content? Adjust the Template to look like this:

<html>
    <head>
        <title>{% container page_title %}</title>
    </head>
    <body>
        {% container page_body as content %}
        {% if content %}
            <p>{{ content }}</p>
        {% endif %}
        <p>The time is {% now "jS F Y H:i" %}.</p>
    </body>
</html>

Now go edit your Page. Two new fields called “Page title” and “Page body” have shown up! You can put anything you like in here and have it show up in the appropriate places when the page is rendered.

Congrats! You’ve done it!

Project Versions

Table Of Contents

Previous topic

Tutorials

Next topic

Using Shipherd in the Admin

This Page