Reputation: 768
I'm having a slight problem where my Django media tag isn't working properly.
This doesn't return the path I expect - which would be '/media/uploads/image_name_goes_here/
', and instead I get '/uploads/image_name_goes_here/
' even though I have specified in my settings.py that the MEDIA_URL = '/media/'
.
My upload_to
path in the models for the Image is the following function..
def img_path(instance, filename):
return ('uploads/%s' % (filename))
class Image(models.Model):
...
image_url=models.ImageField(upload_to=img_path,null=True)
...
My html: <img src='{{ MEDIA_URL }}/{{ Image.img_path }}'/>
Any ideas on why the 'media/' bit of the URL does not show up?
Upvotes: 0
Views: 689
Reputation: 599450
You don't have MEDIA_URL in the context of your template; it's not there by default.
Note however that you don't need it, and you shouldn't be accessing the field like this. Use the url
attribute:
<img src='{{ Image.img_url.url }}'>
Upvotes: 1