Тёмный

HTMX, AlpineJS and Django Messages - Adding Toast / Alert messages in HTMX Responses 

BugBytes
Подписаться 27 тыс.
Просмотров 10 тыс.
50% 1

In this video, we'll look at how to integrate HTMX with Django's Messages Framework, and will add a toast message to our HTMX responses that displays feedback to users on particular actions.
Messages in Django are used to display flash messages on the page - one-time messages that give feedback to users.
We'll see how to use an HTMX Out-of-Band swap to swap in message content on Django responses. We'll style up our Toast / Alert with TailwindCSS, and we'll use AlpineJS to control display of these toasts.
We'll also see a cool trick with Alpine's x-init directive, where we use that to dismiss our toast message after a period of time has elapsed (for example, 2 seconds).
Starter Code (see 'final' branch): github.com/bugbytes-io/django...
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:47 Project Setup
03:32 Adding messages to Django views
05:48 Add TailwindCSS Toast template
10:10 Add toast partial as HTMX OOB swap in HTMX Response
13:09 Changing Toast Positioning with TailwindCSS
14:47 Adding Alpine.js component to dismiss toast
17:32 Using messages error method in Django view
18:42 Dismissing toast with setTimeout and x-init directive
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
ko-fi.com/bugbytes
▶️ Full Playlist:
• Django & HTMX
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: bugbytes.io/posts/
👾 Github: github.com/bugbytes-io/django...
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Starter Code: github.com/bugbytes-io/django...
Django Messages Framework: docs.djangoproject.com/en/4.1...
Tailwind Toast: flowbite.com/docs/components/...
AlpineJS Installation: alpinejs.dev/essentials/insta...
AlpineJS x-init: alpinejs.dev/directives/init
#django #python #htmx #alpinejs

Опубликовано:

 

26 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 48   
@golvmopp
@golvmopp 4 месяца назад
You have no idea how valuable your videos have been for me. Thanks!
@bugbytes3923
@bugbytes3923 4 месяца назад
Thanks a lot! Really happy to hear that.
@UkkaOp7
@UkkaOp7 Год назад
I was looking for guides on how to do this just yesterday, thank you man
@Coden69
@Coden69 Год назад
amazing content
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot for watching!
@Luxun117
@Luxun117 Год назад
Great explanations. Well done dude. Keep up the good work.
@bugbytes3923
@bugbytes3923 Год назад
Thank you very much!
@valentino7057
@valentino7057 Год назад
Great work man. I'm learning a ton from you. It is also one of my request too!
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot man!
@rprana12777
@rprana12777 5 месяцев назад
Just implemented, thank you for the great explanation!
@bugbytes3923
@bugbytes3923 5 месяцев назад
Thanks so much, glad to hear it!
@skyhappy
@skyhappy Год назад
Django + htmx + alpine. The fastest way to bang out a full stack side project
@bugbytes3923
@bugbytes3923 Год назад
Yes!
@umairsarwar7472
@umairsarwar7472 Год назад
all hail downs to you man,amazing!!!!
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot!!
@JustinSpryce
@JustinSpryce Год назад
Great lesson
@bugbytes3923
@bugbytes3923 Год назад
Cheers Justin!
@SmartC2007
@SmartC2007 7 месяцев назад
Thanks a lot for another great video.
@bugbytes3923
@bugbytes3923 7 месяцев назад
Thanks for watching!
@hroman_codes
@hroman_codes Месяц назад
Thank you!!
@bugbytes3923
@bugbytes3923 Месяц назад
Thanks for watching!
@vincentgaliano
@vincentgaliano 7 месяцев назад
I struggled a full hour, trying to understand why the click on the cross didn't work for me, although a click outside worked... I just was I wrote @click: instead of @click=... 😂😂😂 Thank you for all the great videos by the way !
@bugbytes3923
@bugbytes3923 6 месяцев назад
Haha - well done for solving it - these small syntax issues trip me up a lot too 😂
@repotranstech9614
@repotranstech9614 Год назад
Cool video.
@bugbytes3923
@bugbytes3923 Год назад
Thank you!
@TomislavMiletic
@TomislavMiletic 10 месяцев назад
So many hidden gems in your channel, thank you. Maybe you could show how to use this with add to cart / update / delete feature :)
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks a lot Tomislav! Will look into that suggestion.
@chrisgathuthi1831
@chrisgathuthi1831 Год назад
Great work put in there, I have a question regarding the include tag why does it not work when I try to make a reusable form template
@eagleofsharm
@eagleofsharm 5 месяцев назад
Great👍
@bugbytes3923
@bugbytes3923 5 месяцев назад
Thanks!
@iwswordpress
@iwswordpress 5 месяцев назад
Always great. Is it just me but it works fine in Chrome but not in Edge when I set up initial final at start out of the box as per video?
@franke3562
@franke3562 Год назад
Fantastic content on my favorite Django channel. Would you consider doing some content on Wagtail? I feel many projects would benefit from making use of such CMS instead of relying on the Django admin alone. Cheers.
@bugbytes3923
@bugbytes3923 Год назад
Thank you Frank! I am definitely doing some Wagtail content soon, it's high on my list. Any example Wagtail apps you'd like to see in a video series? Thanks again for watching.
@franke3562
@franke3562 Год назад
@@bugbytes3923 Happy to hear Wagtail is already on your list. I am new to Wagtail. Currently trying it out on an art website I am building for a friend. I think any sort of portfolio website would be a good app example for Wagtail. Or a blog, if need be. Wagtail seems great so far - only their documentation could really be a bit more detailed and complete.🙂
@CarlosSantos-yy5iu
@CarlosSantos-yy5iu Месяц назад
Cool video! What’s the advantage of using Django messages vs just passing the same data through context?
@maheshpol20
@maheshpol20 Год назад
Thanks
@bugbytes3923
@bugbytes3923 Год назад
You're welcome.
@tobidegnon4409
@tobidegnon4409 Год назад
Great video. I did something similar a while back but with a slightly different approach (yours looks simpler), instead of an oob response, on the subscribe event a new request was made to a specific view to retrieve the messages, I don't remember exactly how I did it but I used a trick where the messages were not read by Django on the initial response but were available on the next request. Regarding the problem of some js running only on page load and not after a htmx response, this is something I've encountered quite frequently recently in my projects, I haven't found a solution yet but sometimes re-executing the js script when the htmx:afterSettle event is triggered works.
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot Tobi! Your approach sounds good. Somewhat similar! Good call on the htmx:afterSettle event. I'll look into that a bit more and see if I can do some content around this event for dynamic elements. Thanks again!
@frameff9073
@frameff9073 Год назад
thank
@bugbytes3923
@bugbytes3923 Год назад
You're welcome!
@christolabuschagne4382
@christolabuschagne4382 10 месяцев назад
Had a similar issue returning a bootstrap toast in htmx. Could not close the toast using the X button. Solved it using hyperscript with _="on click remove #{{ id_of_toast }}". Not sure if you can also dismiss after time delay. Just an FYI ;-)
@bugbytes3923
@bugbytes3923 10 месяцев назад
Oh, nice! Excellent way to deal with this, thanks for sharing!
@clauderogers2791
@clauderogers2791 8 месяцев назад
@@bugbytes3923 In a script tag at the bottom of the body: htmx.onLoad(function (content) { initFlowbite(); });
@punkweb
@punkweb 9 месяцев назад
I love htmx, alpine I'm not sold on. Think it'd rather just use small jquery scripts instead
@bugbytes3923
@bugbytes3923 9 месяцев назад
Fair point. jQuery still has a valuable place, agreed!
@reelsergealain
@reelsergealain 9 месяцев назад
Nous on comprend pas anglais là, tu es trop rapide pour nous
Далее
HTMX 1.9 - hx-on Attribute for Responding to Events
16:35
Gradle tutorial for complete beginners
24:48
Просмотров 205 тыс.
Mama Bear Helps Babies Across Road
00:30
Просмотров 1,7 млн
ОБНОВАА?? ЛУТАЕМ МЕГАЯЩИКИ
3:12:14
Просмотров 319 тыс.
HTMX: 3 IRL Use Cases
18:33
Просмотров 106 тыс.
HTMX Is Amazing And This Is Why
7:48
Просмотров 40 тыс.
Database Messages - Django Databases #6
15:18
Просмотров 15 тыс.
Django & HTMX - Dynamic Form Creation and Submission
24:36
HTMX - What they don't want you to know!
13:28
Просмотров 79 тыс.
Mama Bear Helps Babies Across Road
00:30
Просмотров 1,7 млн