In django, there is a url mapper which maps URLs to specific functions (views) which return responses. This strict separation between the file system layout and the URL layout allows great flexibility when writing applications.
All url patterns are stored in one or more
urls.py files, and there is a master
urls.py file which is read by django first.
Django parses the patterns in the order they are written, and stops when it finds a match to the URL being requested by the user. If no matches are found, an error is raised.
In debug mode (activated by setting
DEBUG = True in
settings.py), django will print out a detailed error message when a url requested doesn't match any patterns. In production, however, django will display a normal 404 message.
A url pattern consists of a Python regular expression, followed by a callable (a method or function) to be called when that pattern is matched. This function must return a HTTP response: