Skip to content

Instantly share code, notes, and snippets.

@amites
Created January 8, 2012 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amites/1577472 to your computer and use it in GitHub Desktop.
Save amites/1577472 to your computer and use it in GitHub Desktop.
Django TemplateTag to Return Filename without Directory Information
from django import template
register = template.Library()
@register.filter
def fileNameClean(file, arg):
'''
Return the file name without any directory information.
'''
obj = getattr(file, arg, False)
if obj:
return obj.name[len(file._meta.get_field(arg).upload_to) + 1:]
else:
return file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment