Changeset 3506
- Timestamp:
- 07/31/06 21:57:08 (2 years ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/conf/urls/defaults.py (modified) (1 diff)
- django/trunk/django/core/urlresolvers.py (modified) (3 diffs)
- django/trunk/docs/url_dispatch.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r3477 r3506 71 71 gandalf@owca.info 72 72 Baishampayan Ghose 73 martin.glueck@gmail.com 73 74 Espen Grindhaug <http://grindhaug.org/> 74 75 Brant Harris django/trunk/django/conf/urls/defaults.py
r411 r3506 11 11 pattern_list = [] 12 12 for t in tuples: 13 if type(t[1]) == list: 14 pattern_list.append(RegexURLResolver(t[0], t[1][0])) 13 regex, view_or_include = t[:2] 14 default_kwargs = t[2:] 15 if type(view_or_include) == list: 16 pattern_list.append(RegexURLResolver(regex, view_or_include[0], *default_kwargs)) 15 17 else: 16 pattern_list.append(RegexURLPattern( t[0], prefix and (prefix + '.' + t[1]) or t[1], *t[2:]))18 pattern_list.append(RegexURLPattern(regex, prefix and (prefix + '.' + view_or_include) or view_or_include, *default_kwargs)) 17 19 return pattern_list django/trunk/django/core/urlresolvers.py
r3470 r3506 131 131 132 132 class RegexURLResolver(object): 133 def __init__(self, regex, urlconf_name ):133 def __init__(self, regex, urlconf_name, default_kwargs=None): 134 134 # regex is a string representing a regular expression. 135 135 # urlconf_name is a string representing the module containing urlconfs. … … 137 137 self.urlconf_name = urlconf_name 138 138 self.callback = None 139 self.default_kwargs = default_kwargs or {} 139 140 140 141 def resolve(self, path): … … 150 151 else: 151 152 if sub_match: 152 return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]) 153 sub_match_dict = dict(self.default_kwargs, **sub_match[2]) 154 return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match_dict) 153 155 tried.append(pattern.regex.pattern) 154 156 raise Resolver404, {'tried': tried, 'path': new_path} django/trunk/docs/url_dispatch.txt
r3505 r3506 390 390 .. _generic views: http://www.djangoproject.com/documentation/generic_views/ 391 391 .. _syndication framework: http://www.djangoproject.com/documentation/syndication/ 392 393 Passing extra options to ``include()`` 394 -------------------------------------- 395 396 **New in the Django development version.** 397 398 Similarly, you can pass extra options to ``include()``. When you pass extra 399 options to ``include()``, *each* line in the included URLconf will be passed 400 the extra options. 401 402 For example, these two URLconf sets are functionally identical: 403 404 Set one:: 405 406 # main.py 407 urlpatterns = patterns('', 408 (r'^blog/', include('inner'), {'blogid': 3}), 409 ) 410 411 # inner.py 412 urlpatterns = patterns('', 413 (r'^archive/$', 'mysite.views.archive'), 414 (r'^about/$', 'mysite.views.about'), 415 ) 416 417 Set two:: 418 419 # main.py 420 urlpatterns = patterns('', 421 (r'^blog/', include('inner')), 422 ) 423 424 # inner.py 425 urlpatterns = patterns('', 426 (r'^archive/$', 'mysite.views.archive', {'blogid': 3}), 427 (r'^about/$', 'mysite.views.about', {'blogid': 3}), 428 ) 429 430 Note that extra options will *always* be passed to *every* line in the included 431 URLconf, regardless of whether the line's view actually accepts those options 432 as valid. For this reason, this technique is only useful if you're certain that 433 every view in the the included URLconf accepts the extra options you're passing.
