How Django is good for SEO

Django, the venerable Python framework created for the publishing needs of a newspaper Web site, is surprisingly good for organic search engine optimization (SEO).

In fact, Django comes with many options out-of-the-box that sets it apart from other means of building Web applications. These include: beautiful URLs, a plethora of database options, sitemap framework and elegant template design.

Beautiful URLs

Compare an URL from most any Django Web site to those of an ASP or PHP site, and you’ll notice a big difference: You can read the Django URL. And that’s good for you and Google since it’s factored into the page’s importance.

Here’s an example of URLs captured from two newspaper Web sites, the first using Django:

  • (Django):

Some PHP sites come close to Django’s beautiful URLs:

  • (PHP/Drupal):

But what makes Django’s URLs extra nice is the ease at which you can create them.

To design URLs in Django, you need only create a Python module called URLconf. This serves as a “table of contents for your app,” according to the official Django documentation.

Here is an example of what a sample news site’s URLconf looks like (taken from Django documentation):

from django.conf.urls.defaults import *

urlpatterns = patterns('', 
    (r'^articles/(\d{4})/$', 'mysite.views.year_archive'),
    (r'^articles/(\d{4})/(\d{2})/$', 'mysite.views.month_archive'),
    (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'mysite.views.article_detail'),

All URLs are mapped to their views using regular expressions. Each view is passed a request object, which could be a story slug and date. If a view doesn’t exist for that URL, a 404 is returned.

But most importantly for SEO, the URL contains a “slugified” version of the content’s headline. A slug is a newspaper term for a short name given to a story that is in production.

Django has a special model field called slugField that contains only letters, numbers, underscores or hyphens — perfect for creating URLs.

Another bonus: Visit the Knoxnews URL mentioned earlier and go through the directory structure:

  • Stories for day:
  • Stories for month:
  • Stories for year:
  • Story archive:

Since there is a view for each piece of the URL, users (and search robots) can traverse the entire structure and not return a 404.

Now try this with the News-record URL; it doesn’t work quite the same.

Database model API

Your Web site’s SEO is only as good as its content.

Building your Web site in Django allows for an easy way to define custom database models for common things like:

  • X number of characters
  • Text fields
  • URLs
  • Integers
  • Dates
  • Images and files
  • Time
  • States
  • Email addresses

By tailoring your models to the content you’re wanting to display, you can create rich pages that will rank high for SEO. For instance, you can create fields for specific meta tags like keywords or description. Or you can have a field to display a page title optimized differently than the name of your content (like a blog entry or news story).

This makes Django infinitely better than hacking WordPress or another off-the-shelf CMS for common content publishing.

Elegant template design

Django’s templating system allows for a distinct separation of programming logic, aside from basic “for” and “if” statements, from markup and the display of content.

Like general Web standards theory, which dictates design, behavior and markup (HTML) should be separated into CSS, JavaScript and HTML, breaking apart the data in Django allows for a very clean presentation of content for search engines. Less markup means faster load-times, better accessibility and it makes it easier for search engines to find relevant content.

Django sitemaps

Django’s sitemaps framework makes it quick and easy to create sitemaps that tell search engines how frequently your pages change, as well as the importance for each page. This allows Google and others to crawl your site more intelligently.

The sitemaps framework matches the current Sitemap protocol supported by the largest search engines.

When combined with the ping_google() function, which basically tells Google when your site has new content, the Django sitemaps framework makes for an excellent way to index your site’s content very soon after it’s published to the Web.

In summary, just using Django won’t help your Web site’s SEO. But when combined with well-crafted, compelling content, Django’s URLs, database API options, sitemaps and elegant template design make a formidable carrot that Google, Yahoo! and others will have a difficult time resisting.

Read full article at “Entries for Django tag |”

Leave a comment