Failed to get the "next" parameter in the query string using Tornado's self.get_argument () method?
As far as I know, Tornado will add the "next" parameter to the query string, automatically representing the original url that triggers the redirect. And we can use it to redirect the user to the page where he / she wants to visit.
So I tried to build my post()
method LoginHandler
like this:
class LoginHandler(tornado.web.RequestHandler):
def get(self):
pass #some code here
def post(self):
[...] #some code here:verify user identity
#if passed the verification
self.set_secure_cookie("username", username)
#redirect the user back to the page he wanna visit
self.redirect(self.get_argument("next", "/"))
But the redirect doesn't work. It always redirects the user back to the root url " /
". It seems that the argument "next" was not found and the method get_argument()
always returns the default url " /
".
To prove my suspicion, I tried to quit self.request.arguments
using the python engine logging
and finally confirmed: there is no "next" argument, really .
MY QUESTION:
- How can I take full advantage of the "next" parameter to redirect users back to my page?
Addition:
- I found a similar question on StackOverflow: The URL parameter of the following Tornado query string . He recommends moving this redirect to the LoginHandler get method.
My DOUBTS:
When someone clicks the "Login" button, the browser sends pairs (username, password)
to the server using post()
. The method get()
, on the other hand, will not be activated during the period. And so how can it do the redirection?
source to share
No one has answered this question yet
See similar questions:
or similar: