带有ajax的django:函数未从源文件加载

时间:2019-11-07 14:08:48

标签: jquery django django-ajax-selects

在我的Django项目中,我试图使用jQuery添加日期选择器。当我在浏览器中加载页面时,控制台会给我一个错误:

  

未捕获的TypeError:$(...)。datepicker不是函数

我在一个简单的HTML页面中尝试了相同的AJAX代码,并且在那里工作正常。为什么此datepicker()函数无法从源位置加载到Django中?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <title>Hello, world!</title>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
  <script>
    $(function() {
      $("#datepicker").datepicker();
    });
  </script>
  <p>Date: <input type="text" id="datepicker"></p>
  {% block contents %} {% endblock %}
</body>
</html>

1 个答案:

答案 0 :(得分:0)

让我们单击链接click  下载datepicker软件包并将js文件中的任何一个导入到模板中

这将解决您的问题