Skip to content

Instantly share code, notes, and snippets.

@diofeher
Created February 12, 2010 22:24
Show Gist options
  • Save diofeher/303048 to your computer and use it in GitHub Desktop.
Save diofeher/303048 to your computer and use it in GitHub Desktop.
from django.template.defaultfilters import slugify
def slugify_file_name(filename):
'''
Slugify a file name
Use case:
>>> slugify_file_name('/home/diofeher/R5drgébvśdv_SVSvxpoj x,se.jpg')
u'/home/diofeher/r5drgebvsdv_svsvxpoj-xse.jpg'
'''
path, file_name = split(filename)
file_name, pic_ext = splitext(file_name)
file_name = slugify(file_name)
return join(path, file_name + pic_ext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment