Question

I have djando login url, after user loggedin, its getting called as bellow:

(r'^$', RedirectView.as_view(url= '/home/')),

I want to pass loggedin username in above url , such as

(r'^$', RedirectView.as_view(url= '<username>')),

Please suggest.

Was it helpful?

Solution

Would recommend deriving the RedirectView class in a view, like this:

class HomeRedirectView(RedirectView):
    pattern_name = 'home'

    def get_redirect_url(self, *args, **kwargs):
        return "/user/{}/".format(self.request.user)

In urls.py:

(r'^$', HomeRedirectView.as_view()),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top