views:

29

answers:

1

In my model i have a method like so:

class Content(models.Model):
    #...
    def get_file(self):
        file = open('path/to/file','r')
        return File(file)

I am attempting to access this method and the file object in my template like so:

{{ content.get_file.url }}

I am not getting any error but I am also not getting any output. It just returns nothing where there should be a url.

Am I missing something here?

A: 

What you're asking for doesn't make sense. If you are opening an file in an arbitrary location there will be no correlating URL (that Django knows about, at least).

My suggestion would be to simply provide a get_file_url method too.

SmileyChris
I was reading from here: http://docs.djangoproject.com/en/1.1/topics/files/#the-file-object and later I have found this: http://code.djangoproject.com/ticket/11597 so have worked around my problem
rvause
How frustranting - incorrect docs are worse than no docs!Glad you got it solved.
SmileyChris