How to redirect to the original url after login in Tornado
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
If i open a url required login to access, after the login was done i wish to be redirected to the original url. How can i achieve this in Tornado? I searched in Google but nothing useful found. I used the following code but it does not work.
def LoginHandler(RequestHandler):
if not self.current_user:
self.render("login.html")
else:
self.redirect(self.request.headers["Referer"])
I used the Google developer tool and find that when the url is redirected to login page the 'Referer' field does not exist in the request headers.
python tornado url-redirection
add a comment |
If i open a url required login to access, after the login was done i wish to be redirected to the original url. How can i achieve this in Tornado? I searched in Google but nothing useful found. I used the following code but it does not work.
def LoginHandler(RequestHandler):
if not self.current_user:
self.render("login.html")
else:
self.redirect(self.request.headers["Referer"])
I used the Google developer tool and find that when the url is redirected to login page the 'Referer' field does not exist in the request headers.
python tornado url-redirection
add a comment |
If i open a url required login to access, after the login was done i wish to be redirected to the original url. How can i achieve this in Tornado? I searched in Google but nothing useful found. I used the following code but it does not work.
def LoginHandler(RequestHandler):
if not self.current_user:
self.render("login.html")
else:
self.redirect(self.request.headers["Referer"])
I used the Google developer tool and find that when the url is redirected to login page the 'Referer' field does not exist in the request headers.
python tornado url-redirection
If i open a url required login to access, after the login was done i wish to be redirected to the original url. How can i achieve this in Tornado? I searched in Google but nothing useful found. I used the following code but it does not work.
def LoginHandler(RequestHandler):
if not self.current_user:
self.render("login.html")
else:
self.redirect(self.request.headers["Referer"])
I used the Google developer tool and find that when the url is redirected to login page the 'Referer' field does not exist in the request headers.
python tornado url-redirection
python tornado url-redirection
edited Nov 26 '18 at 11:47
Vadim Kotov
4,84863549
4,84863549
asked Nov 22 '18 at 2:52
Ke LuKe Lu
367
367
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you're using @web.authenticated to require login on your handlers, it will redirect the user to the login page with the current url in the next parameter.
For example, if you request for /protected/page, and if you're not logged in, you'll be redirected to the login page with this url - /login?next=/protected/page.
In your login handler check for the next parameter and redirect.
self.redirect(self.get_query_argument('next', '/default/url/if/next/is/empty'))
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423212%2fhow-to-redirect-to-the-original-url-after-login-in-tornado%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you're using @web.authenticated to require login on your handlers, it will redirect the user to the login page with the current url in the next parameter.
For example, if you request for /protected/page, and if you're not logged in, you'll be redirected to the login page with this url - /login?next=/protected/page.
In your login handler check for the next parameter and redirect.
self.redirect(self.get_query_argument('next', '/default/url/if/next/is/empty'))
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
add a comment |
If you're using @web.authenticated to require login on your handlers, it will redirect the user to the login page with the current url in the next parameter.
For example, if you request for /protected/page, and if you're not logged in, you'll be redirected to the login page with this url - /login?next=/protected/page.
In your login handler check for the next parameter and redirect.
self.redirect(self.get_query_argument('next', '/default/url/if/next/is/empty'))
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
add a comment |
If you're using @web.authenticated to require login on your handlers, it will redirect the user to the login page with the current url in the next parameter.
For example, if you request for /protected/page, and if you're not logged in, you'll be redirected to the login page with this url - /login?next=/protected/page.
In your login handler check for the next parameter and redirect.
self.redirect(self.get_query_argument('next', '/default/url/if/next/is/empty'))
If you're using @web.authenticated to require login on your handlers, it will redirect the user to the login page with the current url in the next parameter.
For example, if you request for /protected/page, and if you're not logged in, you'll be redirected to the login page with this url - /login?next=/protected/page.
In your login handler check for the next parameter and redirect.
self.redirect(self.get_query_argument('next', '/default/url/if/next/is/empty'))
answered Nov 22 '18 at 7:06
xyresxyres
10.1k32446
10.1k32446
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
add a comment |
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
Thanks for for your response. I have not use the @web.authenticated decorator but implement my own access control layer. But i finally achieve this inspired by your answer.
– Ke Lu
Nov 23 '18 at 5:59
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
I add a new 'next' argument to the login uri whose value is the currently request one in the redirect when a user is not logged, and write this argument to the login page when rendering and when the user is logging i send this argument along with the user password info and finally i can do the redirect using this extra argument.
– Ke Lu
Nov 23 '18 at 6:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423212%2fhow-to-redirect-to-the-original-url-after-login-in-tornado%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown