jquery - Reference other static file in django javascript file -
i need load file function use telephone autoformatter library (intl tel input) when tried in standalone html page, worked fine, when i'm trying in django project, file isn't loading , think it's because it's not finding in path.
main.js , utils.js both in static directory of project i'm not sure why can't find utils.js file.
main.js:
$(document).ready(function() { $("#phonenumber").intltelinput({ utilsscript: "utils.js" }); });
what in cases need reference server-side paths in javascript set "app" object in uppermost template, can reference in javascript files loaded after, typically require.js.
example:
# base.html (upper-most template) <!doctype html>{% load static staticfiles %} <html> <head>. . .</head> <body> . . . <script> var myapp = { staticurl: '{{ static_url }}' } </script> <script src="{% static 'js/some-file.js' %}"></script> </body> </html> # some-file.js 'use strict'; $(document).ready(function(){ console.log(myapp.staticurl); });
Comments
Post a Comment