Django and Pretty URLs

SEO is very important these days. Especially for web content. I figured I better add some functionality to make the URLs pretty.

Django and Python have made this very easy for me. Since the addition of the SlugField I can easily add in a new item. You can find reference to it here: http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield

I just added it to the models.py


slug = models.SlugField(max_length=50)

Then updated the urls.py


url(r'^(?P\d+)/(?P[-\w\d]+)$', DetailView.as_view(
mode=PostModel,
template_name="postTemplate.html")),

Did an Alter table to include the new column and add in the field values.
Now I have SEO friendly URLs.


comments powered by Disqus