---
canonical: "https://www.jsolly.com/blog/adding-slugified-urls/"
title: "Adding Slugified URLs: A Step-by-Step Guide to Updating Your URLs"
description: "Learn how to add slugified URLs to your website by updating templates and views. Follow this step-by-step guide for easy implementation."
author: "John Solly"
published: "2022-02-02T15:38:26.000Z"
updated: "2022-02-02T15:38:26.000Z"
---

<a id="adding-slugified-urls-a-step-by-step-guide-to-updating-your-urls"></a>

# Adding Slugified URLs: A Step-by-Step Guide to Updating Your URLs

![A banana slug](https://d1d7p8ufhgz4ld.cloudfront.net/media/post_metaimgs/banana-slug.jpeg)

As of today, each post's url in the address bar is a slug such as 'adding-slugified-urls' instead of the post id...e.g.

post/15

This improves SEO (and makes the share links a lot more comprehensible). This involved modifying A LOT of files and broke tons of stuff before I fixed it. Here is an example of how my urls.py changed:

![Code changes needed to slugify posts. The left side of the image shows the before and the right side shows the after.](https://d1d7p8ufhgz4ld.cloudfront.net/media/post_imgs/slugified_code_changes.png)

After adding a new slug field to the post model, you add it to the post form as a text field. This allows you  to set the slug to whatever you want.

![Create post view showing slug field](https://d1d7p8ufhgz4ld.cloudfront.net/media/post_imgs/create_post_slug_field.png)

Because the url changes, you need to update all of your templates so the hrefs to posts reference the post.slug instead of post.id.

Finally, an update to views.py file ensures a db lookup of a post used the slug for a unique lookup instead of the post id.

`post = Post.objects.get(slug=self.object.slug)`

Everything seems works so far!

February 2, 2022 in [Web Dev](https://www.jsolly.com/blog/category/web-dev/)

Updated February 2, 2022
