bblanchon / django-htmx-messages-framework

Django+HTMX: integration with the messages framework
https://blog.benoitblanchon.fr/django-htmx-messages-framework/
MIT License
51 stars 11 forks source link

toast doesn't appear when redirecting #3

Closed oussama-he closed 1 year ago

oussama-he commented 1 year ago

I'm using the oob approach found in oob branch and it works correctly with me, except in one case where the toast doesn't appear.

I have a view that looks like the below:

@login_required
def delete_category(request, pk):
    category = get_object_or_404(Category, pk=pk)
    category.delete()
    # doing some stuff also ... 

    messages.success(request, "Category successfully deleted.")
    response = HttpResponse()
    response["HX-Redirect"] = reverse_lazy("core:main")
    return response

What's wrong with my view and how can I fix it? Thank you in advance.

bblanchon commented 1 year ago

Hi @oussama-he,

Thank you very much for reporting this issue. I added an if statement to check if the HX-Redirect header is present. Please pull the oob branch again and let me know if that fixed your issue.

Best regards, Benoit

oussama-he commented 1 year ago

I've tried the new solution, but it didn't work for me. I tried this #4 and it works now.

bblanchon commented 1 year ago

Cool. Thanks!