Join a list with a string, like Python's ``str.join(list)``.
(value, arg, autoescape=True)
| 610 | |
| 611 | @register.filter(is_safe=True, needs_autoescape=True) |
| 612 | def join(value, arg, autoescape=True): |
| 613 | class="st">""class="st">"Join a list with a string, like Python&class="cm">#x27;s ``str.join(list)``."class="st">"" |
| 614 | try: |
| 615 | if autoescape: |
| 616 | data = conditional_escape(arg).join([conditional_escape(v) for v in value]) |
| 617 | else: |
| 618 | data = arg.join(value) |
| 619 | except TypeError: class="cm"># Fail silently if arg isn't iterable. |
| 620 | return value |
| 621 | return mark_safe(data) |
| 622 | |
| 623 | |
| 624 | @register.filter(is_safe=True) |