Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, get_absolute_url method for file object

def get_absolute_url(self):
        return "/uploads/%i" % self.id

It's not what I want but This is far as I can think of. I need a link for my files (like.../photo.jpg)

I just learned how to get feeds from my django website. And I want this jpeg's absolute url.

http://myDjangoWeb/uploads/goodies_89087_1211864024_1.jpeg

How can I get this file's absolute url.....self.?????

like image 896
Ghostino Doggio Avatar asked Apr 17 '12 14:04

Ghostino Doggio


People also ask

What is Get_absolute_url in Django?

Django documentation says: get_absolute_url() method to tell Django how to calculate the canonical URL for an object.

How can I get full URL in Django?

Use handy request. build_absolute_uri() method on request, pass it the relative url and it'll give you full one. By default, the absolute URL for request. get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.

How do I reverse in Django?

reverse() If you need to use something similar to the url template tag in your code, Django provides the following function: reverse (viewname, urlconf=None, args=None, kwargs=None, current_app=None)


1 Answers

Just use .url property of the file field.

See "Managing files" in Django documentation.

like image 190
vartec Avatar answered Oct 16 '22 19:10

vartec