Home:ALL Converter>Twisted web - redirects in request

Twisted web - redirects in request

Ask Time:2011-11-15T05:01:33         Author:Joe Doherty

Json Formatter

I was wondering if it is possible to redirect from within a render method in twisted web.

I have tried the various ways of redirecting and have only found it documented when used in the getChild method.

Basically I am checking to see if a user is logged in and if it isn't then forward the user onto a different Resource.

    def render_GET(self, request):
        player = getPlayer(request)
        if player.loggedIn():
            return Redirect("play")
        else:
            return Redirect("login")

I have looked all over but I am unable to find a well documented example on twisted documents.

I am not sure if I need to change my approach to this and I am new to twisted web. Any help would be greatly appreciated.

Thank you

Author:Joe Doherty,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8128045/twisted-web-redirects-in-request
yy