Field of Slugs

I’ve been working a bit with Django lately- the website building framework built in Python.  It’s pretty awesome- automating quite a bit of the tedious tasks a developer would otherwise have to do on their own.

Rss feeds, url routing, templating, even a pre-packaged admin panel- all included.  However, there is still a learning curve, and some things can catch you by surprise.

The main hurdle for me has been the url routing.  It’s all regex based, and once it’s all set up, it makes everything easier- creating pretty url strings for your different pages based off the content you’ve created.  However, the links are created via ‘slug’ fields, and that’s where I found my first quirk.

I had no idea what a slug field was- basically, it can be set up (via a cool little utility called autopopulate) so that it removes anything non-url friendly from a title, and saves it for use as that page’s permalink.  So if it’s a blog titled “This blog is totally awesome!”, the slug field would be “this-blog-is-totally-awesome”, which would then be the permanent home for that blog (you can configure the slugfield- a Django built-in- to use underscores or dashes between words).

But for some reason, my slugfields weren’t matching up with my titles.  It wasn’t a huge issue, as it didn’t break anything, but seemed odd.  I’m new to Django, and Python in general, so I assumed I messed something up.  After double checking all my code, I double checked the docs, and finally found the answer: when a slugfield has auto-populate enabled, it eliminates “uninteresting” words.  There’s a whole list in the Django docs- but basically, words like ‘is’, ‘and’, and so on are automatically omitted, in order to keep the link short, but also relevant.

So if your slugfield isn’t matching up, don’t worry- that’s by design.  If it’s an issue, just make sure to make the slugfield editable (by registering it with the and you can always change it manually.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s