sanghmitra
sanghmitra

Reputation: 21

django with ajax: function not loading from source file

In my Django project I'm trying to add a datepicker using jQuery. When I load page in a browser the console gives me an error:

Uncaught TypeError: $(...).datepicker is not a function

I tried the same AJAX code in a simple HTML page and it works fine there. Why is this datepicker() function not loading in Django from source location?

<!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>

Upvotes: 0

Views: 42

Answers (1)

Nj Nafir
Nj Nafir

Reputation: 568

Let's click to the link click download the datepicker package and import any of js file to your templates

This will solve your problem

Upvotes: 0

Related Questions