Ticket #4793: 4793.patch
File 4793.patch, 2.0 KB (added by , 17 years ago) |
---|
-
docs/templates_python.txt
642 642 "Converts a string into all lowercase" 643 643 return value.lower() 644 644 645 When you've written your filter definition, you need to register it with 645 Template filters which expect strings 646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 647 If you are writing a template filter which only expects a string as the first 648 argument, you should use the included decorator ``stringfilter`` which will convert 649 an object to it's string value before being passed to your function:: 650 651 from django.template.defaultfilters import stringfilter 652 653 @stringfilter 654 def lower(value): 655 return value.lower() 656 657 Registering custom template filters 658 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 659 660 After you've written your filter definition, you need to register it with 646 661 your ``Library`` instance, to make it available to Django's template language:: 647 662 648 663 register.filter('cut', cut) … … 658 673 decorator instead:: 659 674 660 675 @register.filter(name='cut') 676 @stringfilter 661 677 def cut(value, arg): 662 678 return value.replace(arg, '') 663 679 664 680 @register.filter 681 @stringfilter 665 682 def lower(value): 666 683 return value.lower() 667 684 668 685 If you leave off the ``name`` argument, as in the second example above, Django 669 686 will use the function's name as the filter name. 670 687 671 Template filters which expect strings672 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~673 If you are writing a template filter which only expects a string as the first674 argument, you should use the included decorator ``stringfilter`` which will convert675 an object to it's string value before being passed to your function::676 688 677 from django.template.defaultfilters import stringfilter678 679 @stringfilter680 def lower(value):681 return value.lower()682 683 689 Writing custom template tags 684 690 ---------------------------- 685 691