Skip to content

Instantly share code, notes, and snippets.

View geoffrey-eisenbarth's full-sized avatar

Geoffrey B. Eisenbarth geoffrey-eisenbarth

View GitHub Profile
@geoffrey-eisenbarth
geoffrey-eisenbarth / middleware.py
Last active March 11, 2025 11:33
HttpVerbViewMiddleware for Django+HTMX
from django.http import HttpRequest, HttpResponse, QueryDict
class HttpVerbViewMiddleware:
"""Adds support for all HTTP verbs.
Notes
-----
Django uses request.GET and request.POST to store QueryDicts
of the request's URL parameters and body respectively. In an
@geoffrey-eisenbarth
geoffrey-eisenbarth / forms.py
Last active January 5, 2025 16:56
Django Form Attributes Mixin
from django.utils.translation import gettext_lazy as _
class FormMixin:
"""Adds extra classes and attributes to HTML widgets."""
# This value will change with your CSS framework.
# https://missing.style/
error_css_class = 'bad color'
@geoffrey-eisenbarth
geoffrey-eisenbarth / middleware.py
Last active September 11, 2024 19:44
Django Middleware for django-template-partials
class HtmxPartialTemplateMiddleware:
"""Adds support for rendering partials with django-template-partials.
NOTES
-----
In order for this middleware to work properly, the following conditions must be met:
1) django-template-partials must be installed
2) Each template must have a partial defined directly in it with a name that coincides
with the HTML id of the element being swapped out. Since django-template-partials does