Opened 20 years ago
Closed 20 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 |
Description
Quick fix:
Index: django/core/meta/__init__.py
===================================================================
--- django/core/meta/__init__.py (revision 635)
+++ django/core/meta/__init__.py (working copy)
@@ -999,7 +999,8 @@
def method_get_file_url(field, self):
if getattr(self, field.name): # value is not blank
import urlparse
- return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.name)).replace('\\', '/')
+ fname = getattr(self, field.name)[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):
Note:
See TracTickets
for help on using tickets.
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 :)