provides view configuration options
If you publish a Django app, your users may want to have some degree of freedom in their configuration. In this case, it would be a good idea to add some hooks to your view for the configuration options you think the user might want to change. You can do this with an extra urlconf parameter.
The more common configuration code in an application is the template name:
def my_view (Request, Template_name): var = do_something () return Render_to_response (template_name, {' var '): var})
Learn about the additional options for prioritizing between snapping values and extra parameters
When a conflict occurs, the extra urlconf parameter takes precedence over the catch value. That is, if urlconf catches a named group variable with the same name as an extra urlconf parameter, the value of the extra urlconf parameter is used.
For example, the following urlconf:
From django.conf.urls.defaults import *from mysite Import viewsurlpatterns = Patterns (', R ' ^mydata/(? P
\d+)/$ ', Views.my_view, {' id ': 3}),)
Here, both the regular expression and the extra dictionary contain an ID. Hard-coded (extra dictionary) IDs will be used first. This means that any request (for example,/mydata/2/or/mydata/432432/) will be set to 3 for the ID, regardless of the value that can be captured in the URL.
Smart readers will find that in this case, it is a waste of time to write a catch in a regular expression, because the value of the ID is always overwritten by the value in the dictionary. Yes, we're just saying this to keep you from making such a mistake.
Special cases in debug mode
When it comes to building urlpatterns dynamically, you might want to use this technique to modify the behavior of URLconf in Django's debug mode. To do this, simply check the value of the DEBUG configuration item at run time, such as:
From django.conf import settingsfrom django.conf.urls.defaults import *from mysite Import viewsurlpatterns = Patterns ("', (R ' ^$ ', views.homepage), (R ' ^ (\d{4})/([a-z]{3})/$ ', views.archive_month), if settings. DEBUG: urlpatterns + = Patterns (', (R ' ^debuginfo/$ ', views.debug), )
In this example, the URL link/debuginfo/only works if your DEBUG configuration item is set to True.