Uncaught ReferenceError: $ не определен в консоли
Я пытаюсь добавить div при выборе флажка в шаблоне dajngo, но продолжаю получать Uncaught ReferenceError: $ is not defined в консоли
шаблон:
{% extends 'base_layout.html'%}
{%load static%}
{% block content %}
<div class="inventory-content">
<div class='category'>
<div>Categories</div>
<div class='category-checkbox'>
{%for category in categories%}
<input type="checkbox" id="{{category.id}}" name="{{category.name}}" value="{{category.id}}">
<label for="{{category.name}}"> {{category.name}}</label><br>
{%endfor%}
</div>
</div>
<div class='items'></div>
</div>
<script>
$('.category-checkbox input[type="checkbox"]').click(function (){
if ($(this).is(':checked')) {
// Add the element to the div with an id identifier
$('.items').append('<div id="[{{category.id}}]">123</div>');
} else {
// Remove the element from the div targeted by the id identifier
$('.items #[{{category.id}}]').remove();
}
});
</script>
{% endblock %}
jquery в django имеет aliased to django.jQuery вместо $. Если вы хотите использовать $ вместо этого, вы можете сделать что-то вроде этого:
(function($) {
//do some stuff with $ here
})(django.jQuery);