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).