This article describes how to use default view parameters in Django's URLconf. Django is the most famous Python web development framework, for more information, see the next convenient feature. You can specify the default parameters for a view. In this way, the default value is used when this parameter is not assigned.
Example:
# Urls. pyfrom django. conf. urls. defaults import * from mysite import viewsurlpatterns = patterns ('', (R' ^ blog/$ ', views. page), (R' ^ blog/page (? P
\ D +)/$ ', views. page),) # views. pydef page (request, num = '1'): # Output the appropriate page of blog entries, according to num. #...
Here, both URL expressions point to the same view views. page, but the first expression does not pass any parameters. If the first style is matched, the page () function uses the default value "1" for the num parameter. If the second expression matches successfully, page () the function uses the num value passed by the regular expression.
(Note: we have noticed that the default parameter value is '''1', not an integer ''1 ''. To maintain consistency, the value captured to ''num'' is always a string.
As explained above, the combination of this technology and configuration options is common. The following example is somewhat improved than the example in the section "view configuration options.
Def my_view (request, template_name = 'mysite/my_view.html '): var = do_something () return render_to_response (template_name, {'var': var })