user8495738
user8495738

Reputation: 147

Django: Load javascript

I try to load the bootstrap-datepicker.js (Located: ...\AEB\static\date_picker\js)

    {% load staticfiles %}
<script type="text/javascript" src="{% static "Leaflet_modi.js" %}"></script>
<!-- Files for date time picker---------------------->
<link rel="stylesheet" href="{% static 'date_picker/css/datepicker.css' %}" type = "text/css"/>
<script type="text/javascript" src="{% static "date_picker/js/bootstrap-datepicker.js" %}"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script type="text/javascript">

$(document).ready(function () {
    $('#Start_Date').datepicker({
        format: "dd/mm/yyyy"
    });
});
$(document).ready(function () {
    $('#End_Date').datepicker({
        format: "dd/mm/yyyy"
    });
});

</script>

Here is my project structure:

enter image description here

But I always get the following error message: "Uncaught TypeError: $(...).datepicker is not a function"

But I do not get any 404 (see image below)

enter image description here

Where is my mistake? Thanks for your help.

Upvotes: 0

Views: 1331

Answers (2)

M.ike
M.ike

Reputation: 113

You need to call jquery first,

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script type="text/javascript" src="{% static "Leaflet_modi.js" %}"></script>
 <!-- Files for date time picker---------------------->
 <link rel="stylesheet" href="{% static 'date_picker/css/datepicker.css' %}" type = "text/css"/>
 <script type="text/javascript" src="{% static "date_picker/js/bootstrap-datepicker.js" %}"></script>

 <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

Upvotes: 1

user9818446
user9818446

Reputation:

I thing your routing in false!!

If you have some files like this :

-<project folder>
----<project-config-folder>
--------setting.py
--------    .
--------    .
--------    .
-------<app-name>
-----------views.py
-----------models.py
--------     .
--------     .
--------     .
--------static
--------------posts
--------------------a.jpg
--------   .
--------   .
--------   .

You can use like this to set file path :

<img src="{% static "posts/a.jpg" %}" alt="My image"/>

Upvotes: 0

Related Questions