I have been warned that this is subjective and likely to be closed, but seems an essential question that I haven't seen addressed.
I am currently coding webapps in django and using a bit of javascript to so this and that. Naturally, I sometimes want my javascript apps from knowing the context of my Django template, so the way I've been doing it is hardcoding the js into the .html file.
Example
<script>
var my_var =
Clearly this is ugly as all hell as it forces me to keep my javascript code inside of the .html file. I'd like to make my .js file separate and load it.
Clearly thee are some options like write a function that takes arguments that can be captured in the template then passed.
e.g.
var my_var =
myFunctionFromScript(my_var)
Is this the best way to be doing this? Is there a better pattern? What are others doing?
Thanks for your help.
-Joe
Aucun commentaire:
Enregistrer un commentaire