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.

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

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!

Comments

Back to Home
John Solly Profile Picture
John Solly Profile Picture

John Solly

A hands-on AI practitioner who transitioned to a CTO role to broaden my impact.

Most of my career has been dedicated to developing spatial systems at Esri, startups, and federal agencies. Currently, I lead technology strategy for Leidos' Health IT division, supporting agencies such as SSA, VA, and HHS.

My primary focus is the convergence of spatial computing and AI, enabling machines to interpret the physical world and applying these capabilities to meaningful missions.

Please reach out if you are interested in spatial systems or advancing AI within the federal government.