Django Warn on Refresh and Leaving Page with JS Django.How

Author avatar wrote on 30/05/2022

Redirect (will prevent resubmitting the form)


from django.shortcuts import redirect
return redirect(f'/customer/{pk}')


WAY 1: Prevent by passing paraments

base.html


    {% if warn_before_leaving_page %}
        
    {% endif %}


    {% if warn_before_leaving_page_or_refresh %}
        
    {% endif %}

views.py


    context = {
        'warn_before_leaving_page': True,
        'warn_before_leaving_page_or_refresh ': True,
    }