【发布时间】:2015-08-17 00:38:50
【问题描述】:
我需要将文件加载到函数中以与电话自动格式化程序库一起使用 (Intl tel input) 当我在独立的 html 页面中尝试此操作时,它运行良好,但是当我尝试在 django 项目中执行此操作时,文件只是没有加载,我认为这是因为它没有找到它在路径中的位置。
main.js 和 utils.js 都在我项目的静态目录中,所以我不确定为什么它找不到 utils.js 文件。
main.js:
$(document).ready(function() {
$("#phoneNumber").intlTelInput({
utilsScript: "utils.js"
});
});
【问题讨论】:
-
看看this这个例子是否适合你。
-
您也可以尝试this 选项。除了
{% static 'your_js_here.js' %} -
@DejaVu 在第一个例子中,它怎么知道
upload_path和uploadify_path是什么? -
您在视图中呈现变量,例如
context = {'upload_path': upload_path, 'uploadify_path': uploadify_path}和return render(request, 'template_name.html', context)。如果你从你的 js 文件中创建了 html,你可以扩展一个你想注入你的 js 的 html - 见{% extends %} -
不幸的是,我目前没有机会对此进行测试,也不确定它是否正确修复,但它应该可以工作。如果它不考虑寻址到 IRC 上的 django 频道。
标签: javascript jquery django upload