MENU

Fun & Interesting

Writing Django Middleware (with tests!) | HTMX middleware | IP Blacklist middleware

BugBytes 4,204 1 year ago
Video Not Working? Fix It Now

Better Stack logging video: https://www.youtube.com/watch?v=_FZfjYVhnwA In this video, we look at how to write Middleware in Django applications, and the purpose and flow of these middleware in a Django application's request/response cycle. We'll write a middleware that blocks IP addresses from accessing the app, along with corresponding Django tests for this functionality. We'll also write an HTMX Middleware that interrogates the request headers for an HTMX header, and sets a value on the Django Request object accordingly. ☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲: To support the channel and encourage new videos, please consider buying me a coffee here: https://ko-fi.com/bugbytes 📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀: 00:00 Intro 00:54 Middleware Overview 04:47 Django MIDDLEWARE Setting 05:43 Writing IP Blacklist Middleware class 12:11 Writing tests for the middleware class 19:11 Writing HTMX Middleware class ▶️ Full Playlist: https://www.youtube.com/playlist?list=PL-2EBeDYMIbQXKsyNweppuFptuogJe2L- 𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮: 📖 Blog: https://bugbytes.io/posts/ 👾 Github: https://github.com/bugbytes-io/ 🐦 Twitter: https://twitter.com/bugbytesio 📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻: Better Stack video: https://www.youtube.com/watch?v=_FZfjYVhnwA Django Middleware: https://docs.djangoproject.com/en/5.0/topics/http/middleware/ Django Testing: https://docs.djangoproject.com/en/5.0/topics/testing/ Django override_settings decorator: https://docs.djangoproject.com/en/5.0/topics/testing/tools/#django.test.override_settings HTMX installation: https://htmx.org/docs/#installing HTMX Request Headers: https://htmx.org/docs/#request-headers #python #django #webdevelopment

Comment