For some reason, Django seems to be displaying my ImageField URL strings escaped. See below (ImageWithThumbsFieldFile uses an ImageField behind the scenes, and I tested it with a normal ImageField as well and the problem still existed.)
>>> from … import UserProfile
>>> u = UserProfile.objects.get(pk=1)
>>> u
<UserProfile: johnny's profile>
>>> u.profile_picture
<ImageWithThumbsFieldFile: /static/img/profile_picture.png>
>>> u.profile_picture.url
'http://mysite.com/%2Fstatic%2Fimg%2Fprofile_picture.png'
Notice the escaping in the URL. Now, when I query the MySQL database:
mysql> select * from ..._userprofile;
+----+---------+---------------------------------+------+
| id | user_id | profile_picture | bio |
+----+---------+---------------------------------+------+
| 1 | 1 | /static/img/profile_picture.png | NULL |
| 2 | 2 | /static/img/profile_picture.png | |
The url is not stored as such. So, I do not believe the problem is the data stored in the database (the url is the default).
I have tried escaping with
|safe
and
{% autoescape off %} {% autoescape end %}
to no avail. My setup is Django 1.2.3 with MySQL running under Apache mod_wsgi. The app runs on my staging server under the same setup without issue (also Apache and MySQL). But since the escapes show up in the Python shell, I do not believe the database or server to be the root cause. The good server is running Python 2.7, and the bad server is running Python 2.6.6 (for reasons out of my control…though I doubt that is the issue either).
Any ideas on how to fix this?
As far as I can tell, this is due to Amazon S3 not having folders. For some reason the django-storages app outputs the urls this way. I thought it was wrong, but the images are working. Just pretty weird to see the urls like that.