Django - Почему Sweetify не работает. SweetAlert2

Я следовал документации от Atrox, а потом все еще не работал над моим проектом. Есть идеи?

Я пишу код, как показано ниже.

1. home/views.py

from django.shortcuts import redirect
from django.views.generic import FormView
from attendance.models import Graduates
from home.forms import TicketForm
from django.utils import timezone
from django.urls import reverse
import sweetify

class HomeView(FormView):
template_name = 'home/index.html'
form_class = TicketForm

def form_valid(self, form):
    getId = form.cleaned_data['nomor_ticket']      
    
    try:
        graduate = Graduates.objects.get(ticket_id=getId)
        message_success = 'Congratulations'

        if graduate:
            graduate.attendance = timezone.now()
            graduate.status = True
            graduate.save()
            sweetify.success(self.request, message_success, text='Cool', persistent='Thanks', timer='3000')
            return (redirect('attendance:index', graduate.ticket_id))

    except Graduates.DoesNotExist:
        print('ticket not found')
        return redirect('home:index')

2. templates/base.html

...
<body>
  {% block contents %}{% endblock contents %}
  <script src="https://unpkg.com/flowbite@1.5.3/dist/flowbite.js"></script>
  {% load sweetify %}
  {% sweetify %}
</body>
...

3. core/settings.py

INSTALLED_APPS = [
...
'sweetify'
...
]

SWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'

я думаю, что для сбора css и js файлов нужно использовать collectstatic

запустить команду python manage.py collectstatic

ВНИМАНИЕ: убедитесь, что в файле setting.py

# STATICFILES_DIRS = [BASE_DIR / 'static']
STATIC_ROOT = BASE_DIR / 'static'
Вернуться на верх