title: Substring with split in html template django python
body: <p>I have this model:</p>
  
  <pre><code>def generate_filename(self, filename):
      url = "files/users/%s/%s" % (self.user.id, filename)
      return url
  
  class Upload(models.Model):
      user = modelo.ForeignKey(User, null=True)
      docfile = modelo.FileField(upload_to=generate_filename)
  </code></pre>
  
  <p>Views.py</p>
  
  <pre><code>allfiles = Upload.objects.all()
  </code></pre>
  
  <p>I have a list of uploaded files in django:</p>
  
  <pre><code>&lt;ul&gt;
      {% for item in allfiles %}
          &lt;li&gt;&lt;a href="{{ item.docfile.url }}"&gt;{{ item.docfile.name }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Its showing on html the full path of my file:</p>
  
  <pre><code>files/users/1/test.txt
  </code></pre>
  
  <p>I want to show only <code>test.txt</code></p>
  
  <p>I tryed this:</p>
  
  <pre><code>&lt;ul&gt;
      {% for item in arquivos %}
          &lt;li&gt;&lt;a href="{{ item.docfile.url }}"&gt;{{ item.docfile.name.split('/')[3] }}&lt;/a&gt;&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>but I got <code>Could not parse the remainder: '('/')' from 'item.docfile.name.split('/')[3]'</code></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I tryed to create a file in <code>myapp/templatetags/filename.py</code>:</p>
  
  <pre><code>import os
  
  from django import template
  
  
  register = template.Library()
  
  @register.filter
  def filename(value):
      return os.path.basename(value.docfile.name)
  </code></pre>
  
  <p>In template:</p>
  
  <pre><code>{% load filename %}
  &lt;ul&gt;
      {% for item in allfiles %}
          &lt;li&gt;&lt;a href="{{ item.docfile.url }}"&gt;{{ item.docfile|filename }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>And now I'm getting this:</p>
  
  <pre><code>'filename' is not a registered tag library. Must be one of:
  admin_list
  admin_modify
  admin_static
  admin_urls
  cache
  filaname
  future
  i18n
  l10n
  log
  static
  staticfiles
  tz
  </code></pre>