1

I don't know if it's a bug or a feature, but when I'm on my home page with the contact form anchor
(url = http://localhost:8000/#contact)

After submitting the form, all of these will redirect including the #contact anchor name and I cannot get rid of it:

from django.http import HttpResponseRedirect
from django.urls import reverse
from django.shortcuts import redirect

# Following 3 lines all send back to http://localhost:8000/#contact
return HttpResponseRedirect(reverse('homepage'))
return redirect(reverse('homepage'))
return redirect('/')

# As a test, the following line redirects to http://localhost:8000/account/email/#contact
return HttpResponseRedirect(reverse('account:email'))

I found some people with the opposite issue, trying to add the anchor name, but can't find a related question with my issue

NaturalBornCamper
  • 3,675
  • 5
  • 39
  • 58

1 Answers1

1

A browser preserves a fragment during redirect, you can check out these SO questions/answers:

  1. URL hash is persisting between redirects
  2. URL Fragment and 302 redirects

So, I believe you could try setting an empty fragment in the redirect URL to override page's URL fragment. If it doesn't help then redirect from JS on a successful response.

GProst
  • 9,229
  • 3
  • 25
  • 47