How to display file extension in django template ?

485 views
Skip to first unread message

Ashish Tiwari

unread,
Feb 7, 2014, 2:25:10 AM2/7/14
to django...@googlegroups.com
It's a simple question but i'm not able to find easily. 
How can I display the file extension of uploaded file in template ?

ex : uploaded-filename.jpeg
      {{file.<extension>}} will display "jpeg" in template.

Russell Keith-Magee

unread,
Feb 7, 2014, 9:26:06 AM2/7/14
to Django Users
There isn't anything builtin to do this, but it would be a really to write a custom template tag that was a simple wrapper around os.path.splitext(). See:


For details on how to write a custom template tag.

Yours,
Russ Magee %-)

werefrog

unread,
Feb 7, 2014, 8:33:28 PM2/7/14
to django...@googlegroups.com
Hello,

In that case, I would use a filter that return os.path.splitext(myfile.path)[1] (the result will be '.jpeg' with your example).

Regards,
Michel


Reply all
Reply to author
Forward
0 new messages