I am trying to change the background image of the div dynamically whenever the user uploads the image via ajax.
First I am passing the url of the image through ajax from the view to the template. And then I am changing the url for the css to get the image:
url = 'http://sitename.com/media/' + url;
block.css({
'background-image': 'url('+url+')',
'background-color': ''
});
Now the url becomes like this and this is working as expected:
url = http://sitename.com/media/uploaded_files/thomas.jpg
But when I try to use the {{MEDIA_URL}} as its describe to use in the django template
url = '{{MEDIA_URL}}' + url;
I get a 404 error and the url is changed like this:
GET http://sitename.com/page-modify/67/%7B%7BMEDIA_URL%7D%7Duploaded_files/1449049938_08_images.jpg 404 (NOT FOUND)
How can I use the {{MEDIA_URL}} from the django settings in my template to change the background-image using jquery?
{{ MEDIA_URL }}? In which file?