6.2 Generating URLs in Python and Django Templates

While the practical goal of this chapter is to generate links, the actual goal is to focus on using multiple parts of Django and enforcing DRY.

The goal of DRY is to only ever define any piece of information once. We already have all of our links defined in the URL configuration, which means that we do not want to code links in raw HTML. If we change the regular expression pattern of a URL pattern, we should not have to make any other changes: we do not want to have to change links in each and every template.

The issue, of course, is that we are trying to accomplish the very opposite of what a regular expression pattern typically does: we are not interested in matching a string, we are interested ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.