'WSGIRequest' object has no attribute 'htmx'

Viewed 33

Hi just looking for some help at solving this error in Django whilst trying to call a view that to accept a htmx request. The final result is to display a popup Modal of images from a Gallery when a thumbnail is clicked.

HTMX installed via script in head.

View


    if request.htmx:
        slug = request.GET.get('slug')
        context = {'pictures': Media.objects.filter(slug=slug)}
        return render(request, 'main/gallery-detail.html', context=context)

    context = {'objects_list': Albums.objects.all()}
    return render(request, 'main/gallery.html', context=context)

Relevant html with the button to open gallery of images.

<a class="btn btn-primary" hx-post="{{ request.path }}?slug={{ img.slug }}" hx-target="#modal">
                {{ img.slug }}</a>
{% endfor %}

<div id="modal">{% include "main/gallery-detail.html" %}</div>
0 Answers
Related