I’m running into an issue now where I have a “random” link on my site to see a random user. The way I have it set up is to get the user_id and then use redirect to serve the proper page. The issue I’m running into is if I click the random button multiple times, clicking on back will bring me back to the page before the “random” clicks.
To be more concrete, this is what’s happening:
HomePage, Click Random (go to /user1/), Click Random (go to /user4/), Hit back (end up on HomePage). In this scenario I’d like to end up on /user1/
This is the random view method:
def Random(request):
user = helpers.GetRandomUser()
return redirect('user_display', user_slug=user.username)
The template just has a link to /random/ which gets routed to the above view.
Edit: Apparently it works as expected in Firefox but in Chrome. I’d like it to have the Firefox-like behavior everywhere.
So if I understand you correctly you click two times on a link to the same url (like
/random_user/) and you respond with a random redirect. This seems quite unconventional and it doesn’t sound so wrong that Chrome might view this as a single history entry.To archieve your wanted behaviour across browsers simply generate the random url before you render your random user link.
As you want to use it in multiple views, write a custom template tag:
In your template:
This way every click leads the browser to a different url and will be memorized as seperate history entry.