O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.8.1 NewsLink URL patterns

At the moment, our website uses the primary keys of NewsLink objects in the URL patterns of related views. This practice is frowned upon, and we want to switch to using the SlugField of the NewsLink object, a field we added in Chapter 10: Revisiting Migrations.

The trick to our new URL patterns is that the slug does not uniquely identify the NewsLink object. Instead, the combination of startup and slug does. Our URL patterns thus need to use two slugs to identify the NewsLink. That’s somewhat tricky. All of our pages simply use slug as a variable name in regular expression patterns, and now we have to differentiate between startup_slug and newslink_slug in some instances.

As these views will now be associated with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required