Brand new company site : shift8 + django

Hello!

We have recently completely re-vamped our company website : www.shift8web.ca. We have decided to move away from a conventional CMS and towards a web framework called django.

Some of the challenges encountered were from a systems administration perspective (nginx + varnish + php-fpm). Other challenges faced were migrating all our content / data into a completely different CMS than what we were used to.

Django provides many advantages, namely being a very versatile, customizable, scalable and robust web framework. We created a static html template, integrated the content models and tweaked it until we were happy.

I’ll break down the aspects from a high level to give a brief overview of whats involved in transitioning to django

models

We defined models for as much of the website as possible. Models in django are where you define your dynamically changing data (such as a page title). You can define how many characters each model will contain, what type of model it is and many more customizable options. Breaking down the site into chunks that could be defined by models was key for this project.

Here’s a sample of the front page slider model that holds the images, captions and whatnot :

class FrontSlider(models.Model):
    file = models.CharField(max_length=128)
    title = models.CharField(max_length=256)
    alt = models.CharField(max_length=256)
    caption = models.CharField(max_length=1024)

views

Views are where we interpret the data (GET or POST) and send that data to the template rendering engine to interpret and render within the HTML code. Its pretty straightforward if all you’re doing is rendering data and not manipulating it or receiving user input.

Here is a sample of the “home page” view :

def index(request):
    context = RequestContext(request)
    return render_to_response('main/index.html',
        {'portfolio': PortfolioItem.objects.all(),
        'frontdesc': FrontDescription.objects.all()[:1].get(),
        'slider': FrontSlider.objects.all()},
        context)

Now as soon as you have a contact form that accepts , processes and sanitizes user input then it gets a bit complicated. I’ll leave the examples and actual documentation / instructions for the many people who have already published guides

Essentially you need to define a view for the page that first checks if the request is a POST, then define the form and check if the input is valid. Using the django forms system is quite simple. Integrating captcha is cause for a second post, however.

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():

Django admin backend

One of the main reasons why django is great is that you get to define and create your very own , completely customizable, admin backend! This is great for branding and customizing a CMS solution for a client with very specific needs and technical requirements.

The admin site can have its own branded custom template, and several are available commercially to purchase. The default admin template will do for now. At this point we simply define which models we want to make available in the admin site backend :

from django.contrib import admin
from main.models import *

admin.site.register(FrontSlider)

URLs

One of the last main (high level) things that we want to go over is where to define the url structure that receives browser requests and processes them to the according template view and template page respectively.

The urls.py file is what contains this “index” of directions. You define the admin site url (and how django handles a request for the admin page) here as well :

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^robots\.txt$', lambda r: HttpResponse("User-agent: *\n", mimetype="text/plain"),

You’ll see the admin directive , as well as one for a simple robots.txt query.

We love django and want as many people to get involved in the project as possible! In the end, we love the end result of transitioning our corporate site to django.