14

I am trying to retrieve the absolute path (starting with http://) while calling a FileField at the template.

How can I achieve this ?

ie: {{fl.uploadedfile}} -> returns relative path like media/uploads/ while I want This

Cheers

karthikr
  • 97,368
  • 26
  • 197
  • 188

2 Answers2

15

The Django File object provides several convenience functions/attributes, one of which is the URL associated with the file. In this case, as you pointed out, you're looking for the url attribute.

jds
  • 861
  • 6
  • 14
  • it seems that in the mentioned link there is no reference to an `url` attribute. Did you meant referring to https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield ? – furins Sep 28 '14 at 07:20
9

Just found the answer: adding .url fixes this issue fixes it such as {{fl.uploadedfile.url}}

karthikr
  • 97,368
  • 26
  • 197
  • 188