Context Navigation

Question:

In a url configuration file, we use the first argument to the patterns() function to specify a prefix to apply to each view function , avoiding typing that out for each entry in urlpatterns. but in the practical application, it is quite normal that only part of patterns have the common prefix. In that case, we cann't use a prefix directly for example:

Answer

All Django URL resolver needs is a urlpatterns variable in the url configuration, which is a list of pattern objects returned by the patterns() function. So we can do as the following to make our configuration DRY: