If you're creating or updating a model, consider inheriting from CreateView
or UpdateView
and specifying a success_url
.
If you're really doing a redirect off of an HTTP GET action, you can inherit from RedirectView
and override the get
method (optionally also specifying permanent = False
):
class CountSomethingView(LoginRequiredMixin, RedirectView):
permanent = False
def get(self, request, *args, **kwargs):
# do something
return super(CountSomethingView, self).get(self, request, *args, **kwargs)
Note that it's really bad practice to have a get
action with side-effects (unless it's just populating a cache or modifying non-essential data). In most cases, you should consider using a form-based or model-form-based view, such as CreateView
or UpdateView
as suggested above.