django sweetalert2 activite when the data Inserted succesfully

Viewed 438

I read this https://github.com/Atrox/sweetify-django documentation about sweetify, and i did everything say in the documentation.but everytime the user admin Insert new data, the sweetify didnt activate, did i miss something? I already install it. I am using django 2.2.4

I have this code in my 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>

this is my 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'
1 Answers

After much effort, the problem is a lack of scripts in the HTML:

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

The library needs these to actually display the alerts. No backend errors will be thrown if this is not present

Related