Django - Template Vars in static JS files
In Django, lets say I want to import a javascript file using script src="blah.js"
开发者_如何学CI pass in a template variable {{ business }}. Is there a way for the static javascript file blah.js to access {{ business }}? I can do it with javascript in the html templates but once I call a static script it doesn't work. It seems like it'd be best to separate javascript files I call in multiple templates into a javascript file so I thought it might be possible.
You redesign your code in such a way that in the templates you make calls to javascript functions with the template variables as arguments:
<script type="text/javascript">
x = foo({{ business }}, {{ some_other_variable }});
alert(x);
</script>
精彩评论