Code

Ticket #5160: base.py.diff

File base.py.diff, 664 bytes (added by Esaj, 7 years ago)

Escape spaces in generated URL using urllib.quote

Line 
1Index: django/db/models/base.py
2===================================================================
3--- django/db/models/base.py    (revision 5804)
4+++ django/db/models/base.py    (working copy)
5@@ -358,8 +358,8 @@
6 
7     def _get_FIELD_url(self, field):
8         if getattr(self, field.attname): # value is not blank
9-            import urlparse
10-            return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/')
11+            import urlparse, urllib
12+            return urllib.quote(urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/'))
13         return ''
14 
15     def _get_FIELD_size(self, field):