django filefield return filename only in template

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-21T14:09:39Z Indexed on 2010/04/21 14:13 UTC
Read the original article Hit count: 187

Filed under:
|

I've got a field in my model of type FileField. This gives me an object of type type File, which has the following method:

File.name: The name of the file including the relative path from MEDIA_ROOT.

What I want is something like .filename that will only give me the filename and not the path as well

something like:

{% for download in downloads %}
    <div class="download">
        <div class="title">{{download.file.filename}}</div>
    </div>
{% endfor %}

which would give something like myfile.jpg

thanks

© Stack Overflow or respective owner

Related posts about django

Related posts about django-file-upload