title: Django: how to build an endswith filter
body: <p>I need to render image <strong>adobe_illustrator_file_logo.png</strong> if <code>file.url</code> ends with <code>.ai</code>. </p>
  
  <p>But if <code>file.url</code> ends with other termination like <code>.png</code> for exmaple I'll render the image of the object.</p>
  
  <p>I've searching documentation but apparently there is not a <code>endswith</code> built in filter.</p>
  
  <p>So I ended up playing with <code>ifequals</code> and <code>slice</code> filter. </p>
  
  <p>Logic it is the same: "<em>if string is identical to the last 3 letters do this</em>".</p>
  
  <p>However, it is not working, as nothing gets displayed. </p>
  
  <pre><code>&lt;td&gt;
     {% ifequal cart_item.file.url|default:""|slice:"-3" ".ai" %}
  
          &lt;img src="{% static 'img/admin/adobe_illustrator_file_logo.png' %}"
                     alt=""
                     class="float-left rounded custom_image"&gt;
     {% endifequal %}
   &lt;/td&gt;
  </code></pre>
  
  <p><strong>Note:</strong></p>
  
  <pre><code>&lt;p&gt;{{ cart_item.file.url  }}&lt;/p&gt;
  </code></pre>
  
  <p><strong>HTML renders</strong>: </p>
  
  <pre><code>&lt;p&gt;/media/files/working_precisely.ai&lt;/p&gt;
  </code></pre>
  
  <p>Also, <strong>adobe_illustrator_file_logo.png</strong> renders correctly if it is put outside if condition.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>Created my own filter, but gettting error:</p>
  
  <p><strong><em>TemplateSyntaxError at /cart/<br>
      endswith requires 2 arguments, 1 provided</em></strong></p>
  
  <pre><code>from django import template
  from django.template.defaultfilters import stringfilter
  
  register = template.Library()
  
  @register.filter(is_safe=False)
  @stringfilter
  def endswith(value, suffix):
      return value.endswith(suffix)
  </code></pre>
  
  <p><strong>Template</strong></p>
  
  <pre><code>{% if cart_item.file.url|endswith: ".ai" %}
  
         &lt;img src="{% static 'img/admin/adobe_illustrator_file_logo.png' %}"
                  alt=""
                  class="float-left rounded custom_image"&gt;
  {% endif %}
  </code></pre>