0

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>

3
  • I placed your code in an executable snippet where it works fine. Are there any other errors in the console? Perhaps about the script references leading to 404 errors, or conflicts? Commented Nov 7, 2019 at 14:15
  • here is the solution: stackoverflow.com/questions/36207203/… Commented Nov 7, 2019 at 14:28
  • your solution helped me to find the mistake. Thanks :) @YazanM.Al-Horani Commented Nov 8, 2019 at 5:04

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.