django sweetalert2 活动,当数据插入成功时

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


我的网页中有这段代码


{% 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'


慕村225694
浏览 155回答 1
1回答

元芳怎么了

经过大量的努力,问题是HTML中缺少脚本:<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>库需要这些来实际显示警报。如果不存在,则不会引发任何后端错误
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript