TypeError: $(...).textcomplete не является функцией внутри Django

Я пытаюсь реализовать метод $('textarea-selector').textcomplete из https://github.com/ranvis/jquery-textcomplete/blob/master/jquery.textcomplete.js в виджете Djnago Textarea.

django/forms/templates/django/forms/widgets/textarea.html

{% load static %}

<textarea name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
{% if widget.value %}{{ widget.value }}{% endif %}</textarea>

<script src="js/tasks/jquery-1.10.2.min.js"></script>

<script src="js/tasks/jquery.textcomplete.min.js"></script>
<script type='text/javascript'>
    $('#id_{{ widget.name }}').textcomplete([
    {
        words: ['select', 'from', 'fct_table1', 'fct_table2', 'where', 'column1', 'column2'],
        match: /\b(\w{2,})$/,
        search: function (term, callback) {
            callback($.map(this.words, function (word) {
                return word.indexOf(term) === 0 ? word : null;
            }));
        },
        index: 1,
        replace: function (word) {
            return word + ' ';
        }
    }
])
</script>

Но получаем ошибки:

enter image description here

enter image description here

В то же время, если я делаю то же самое в простом html файле, все работает хорошо:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.10.2.js"></script>
    <script src="jquery.textcomplete.js"></script>

</head>
<body>

<textarea class="textarea" id="textarea" rows="4" cols="50">...</textarea>

<script>

    $('.textarea').textcomplete([
        { // tech companies
            words: ['select', 'from', 'fct_table1', 'fct_table2', 'where', 'column1', 'column2'],
            match: /\b(\w{2,})$/,
            search: function (term, callback) {
                callback($.map(this.words, function (word) {
                    return word.indexOf(term) === 0 ? word : null;
                }));
            },
            index: 1,
            replace: function (word) {
                return word + ' ';
            }
        }
    ]);

</script>
</body>
</html>

Как заставить скрипт работать внутри Django? strong text

<script src="{% static 'js/tasks/jquery-1.10.2.min.js' %} "></script>

Сделайте это для всех внешних скриптов.

Вернуться на верх