Changes between Version 43 and Version 44 of BackwardsIncompatibleChanges
- Timestamp:
- Nov 26, 2005, 5:33:52 PM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BackwardsIncompatibleChanges
v43 v44 369 369 == Changed the way custom template tags and filters are registered == 370 370 371 As of [ ], we changed the way custom template tags and filters are registered. If you've written custom template tags or filters, you'll need to make a couple of changes:371 As of [1443], we changed the way custom template tags and filters are registered. If you've written custom template tags or filters, you'll need to make a couple of changes: 372 372 373 373 === Filter arguments === … … 413 413 If you're using the undocumented template decorators (simple_tag and inclusion_tag), change your calls to be members of the library class. 414 414 415 [INSERT EXAMPLE HERE] 415 register.simple_tag(func) 416 417 register.inclusion_tag('template/name')(func) 418 419 === Change template tags that use filters === 420 421 Filters are compiled at compile time now. 422 423 Old way: 424 {{{ 425 426 class SomethingNode(Node): 427 def __init__(self, filter_string): 428 self.filter_string = filter_string 429 430 def render(self, context): 431 var = render_variable_with_filters(self.filter_string, context) 432 return var 433 434 def do_something(parser, token): 435 filter_string = bits[1] 436 return SomethingNode(filter_string) 437 438 }}} 439 440 New way: 441 {{{ 442 443 class SomethingNode(Node): 444 def __init__(self, filter_expr): 445 self.filter_expr = filter_expr 446 447 def render(self, context): 448 var = self.filter_expr.resolve(context) 449 return var 450 451 def do_something(parser, token): 452 filter_string = bits[1] 453 filter_expr = parser.compile_filter(filter_string) 454 return SomethingNode(filter_expr) 455 456 }}} 416 457 417 458 See [http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters Writing custom template filters] and [http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags Writing custom template tags] for full documentation.