Why setting src of img by jquery in Django does not have to include {{MEDIA_URL}} -


just curious question. in order display image image in {{media_url}}, need in django:

<img src="{{media_url}} + file-url "> 

with jquery, don't have include {{media_url}}:

$('.myimg').attr('src',"file-url"); 

why?

because django don't parse .js files. include media_url in js files should in base template in head section:

<script type="text/javascript">     var mediaurl = '{{ media_url }}'; </script> 

then can use in scripts:

$('.myimg').attr('src', mediaurl + file-url); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -