Opened 18 years ago

Closed 18 years ago

#493 closed defect (fixed)

[patch] FileField.get_foo_url returns absolute path instead url

Reported by: nesh <nesh [at] studioquattro [dot] co [dot] yu> Owned by: Adrian Holovaty
Component: Metasystem Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Quick fix:

Index: django/core/meta/
--- django/core/meta/        (revision 635)
+++ django/core/meta/        (working copy)
@@ -999,7 +999,8 @@
 def method_get_file_url(field, self):
     if getattr(self, # value is not blank
         import urlparse
-        return urlparse.urljoin(settings.MEDIA_URL, getattr(self,'\\', '/')
+        fname = getattr(self,[len(settings.MEDIA_ROOT):] # name is stored with filesystem full path
+        return urlparse.urljoin(settings.MEDIA_URL, fname).replace('\\', '/')
     return ''
 def method_get_file_size(field, self):

Change History (1)

comment:1 by nesh <nesh [at] studioquattro [dot] co [dot] yu>, 18 years ago

Resolution: fixed
Status: newclosed

How stupid of me ;D

My custom function which rename files before posting is storing full paths in image field. When I stored relative paths everything is working OK.

It seems that I need to read documentation again :)

Note: See TracTickets for help on using tickets.
Back to Top