0

I have a simple RedirectView:

class SetDefaultCustomerAccount(LoginRequiredMixin, RedirectView):
    permanent = False

    def get_redirect_url(self, *args, **kwargs):
        # set default account)
        print("FOOO!!!!!!!")
        self.request.user.default_customer_account = get_object_or_404(CustomerAccount, id=self.kwargs['account_id'])
        self.request.user.save()

        return reverse("users:detail",
                       kwargs={"username": self.request.user.username})

Called by a route:

# URL pattern for the setting a default customer account to a user
url(
    regex=r'^set_default_account/(?P<account_id>[0-9]+)$',
    view=views.SetDefaultCustomerAccount.as_view(),
    name='set_default_account'

One detail: the 'default_customer_account' ForeignKey in my User model is optionnal (null=True, blank=True).

In my data I have two CustomerAccount, with ID 1 and 2.

When I GET '127.0.0.1:8000/users/set_default_account/2', my code isn't printing 'FOOO!!!!!!!". Same with '127.0.0.1:8000/users/set_default_account/2'.

Although, I am sure I was getting the right thing in the first call (that is, default customer account changed for logged user).

Question is: do RedirectView has a behavior different, depending on how many time it is called?

Update: Everything works fine with Safari, the problem described appears with firefox. Somebody had similar issue here (but this would not solve my problem).

Community
  • 1
  • 1
bixente57
  • 1,328
  • 4
  • 14
  • 29

1 Answers1

0

Thanks to this thread I've found out that Firefox was caching my 301 redirect pages.

The solution is to set permanent=False in the RedirectView, so that the response will change to 302, and Firefox will not save this redirect in cache.

Community
  • 1
  • 1
bixente57
  • 1,328
  • 4
  • 14
  • 29