How to prevent the page scrolling back to the top after clicking on a button?

I have a small form on django, when the button is clicked it display a django message bellow the form to tell the user that he successfully clicked on the button but it redirect the user in the top of the page. I want the page to stay where it is or redirect where the form is so he can see the message.

<form action="" method="post">
    {% csrf_token %}
    {{ form|crispy }}
    <button type="submit" class="btn btn-dark">Soumettre</button>
</form>

views.py

def home(request):
    if request.method == 'POST':
        form = LeadForm(request.POST)
        
        if form.is_valid():
            nom = form.cleaned_data['nom']
            messages.success(request, "Merci pour votre message. Nous allons vous contactez le plus vite possible.")
    else:
        form = LeadForm()

    return render(request, 'main/index.html', {'form': form})

I tried to add a href="#!" or href="javascript:void(0);" to the button but it is not working either.

Back to Top