Posts

Showing posts with the label filters

All Django Filters used in Templates

Image
  Django Template Engine provides filters which are used to transform the values of variables;es and tag arguments. We have already discussed major   Django Template Tags . Tags can’t modify value of a variable whereas filters can be used for incrementing value of a variable or modifying it to one’s own need. Syntax {{ variable_name | filter_name }} Filters can be “chained.” The output of one filter is applied to the next.  {{ text|escape|linebreaks }}  is a common idiom for escaping text contents, then converting line breaks to <p> tags. Example {{ value | length }} If value is  [‘a’, ‘b’, ‘c’, ‘d’] , the output will be  4 . Major Template Filters in Django This article revolves around various Django Template Filters one can use during a project. Filters transform the values of variables and tag arguments. Let’s check some major filters. add addslashes capfirst center cut date default dictsort divisibleby escape filesizeformat first join last length linenumbers lower make_list r