Mapping URL patterns
Writing custom views is a way for us to perform all of the tasks and services needed to render a page that includes all of the content that we want. Within a view, we can validate against business logic rules to determine how to handle a request.
In this exercise, we will use the year pattern that we wrote earlier in this chapter, to only allow a year greater than 1900. Anything less than that, we will tell Django to serve up a 404 response.
Using simple views
A simple view is also known as a method-based view, which is a callable function in Python.
Follow these steps to map to a simple view in your project:
- In your
/chapter_4/urls.py
file, revert to using the same converter class that we wrote in the Using path converters subsection of this chapter. Reference a view that we will write next in a different file calledpractice_view()
, as highlighted here:# /becoming_a_django_entdev/chapter_4/urls.py ... from django.urls import ..., register_converter...