Resolving URLs
Resolving a URL is the process of taking a relative path or object and obtaining the URL that relates to a unique field such as a primary key. Django's reverse resolution of URL patterns is a method of generating a URL structure using argument values that we provide instead of hardcoding URL paths in places, which can break over time. We can use template tags and statements throughout the project to use the name
argument of a URL pattern. This is encouraged as best practice and follows a DRY design principle, which is less prone to breakage as your project evolves.
Let's discuss how to use the name
attribute to get a reverse resolution pattern.
Naming URL patterns
Using the same custom YearConverter
class and the same my_year_path
URL pattern that we created earlier in this chapter, do the following to configure your URL pattern.
In your /chapter_4/urls.py
file, you should have the path shown in the following code block, using the highlighted name...