数据插入成功时django sweetalert2 activite

django sweetalert2 activite when the data Inserted succesfully

我读了这篇关于 sweetify 的 https://github.com/Atrox/sweetify-django 文档,每次用户管理员插入新数据时,我都做了 documentation.but 中所说的一切,但 sweetify 没有激活,我是不是错过了什么?我已经安装了它。我正在使用 Django 2.2.4

我的 html

中有此代码
{% load sweetify %}
{% sweetify %}
    <form method="POST" action-xhr="/InsertProduct/" enctype="multipart/form-data">
    {% csrf_token %}
    ....
    <button type="submit" name="submit" id="submit">Submit</button>
</form>

这是我的views.py

import sweetify
def InsertProduct(request):
    ....
    insert_data = Product(
       ....
    )
    sweetify.success(request, 'You did it', text='Good job! You successfully showed a SweetAlert message', persistent='Hell yeah')
    insert_data.save()
    
    return redirect('/') # <-- tabbed this line

sweetify.py

from sweetify.templatetags import sweetify
    
sweetify.DEFAULT_OPTS = {
    'showConfirmButton': False,
    'timer': 2500,
    'allowOutsideClick': True,
    'confirmButtonText': 'OK',
}

settings.py

INSTALLED_APPS = [
    .....
    'sweetify',
]
SWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'

经过一番努力,问题是HTML中缺少脚本:

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9">
</script>

图书馆需要这些来实际显示警报。 如果不存在,则不会抛出后端错误