You can change your "Login" so that they always include the current URL as the value of the _next variable in the query string. For example, wherever you create a login link, define it as follows:
A('Login', _href=URL('default', 'user', args='login', vars=dict(_next=URL(args=request.args, vars=request.vars))))
This will add the URL of the current page (including any arguments and vars) to the _next variable in the query string of the login link, which will lead to a redirect to the current page after login.
If you use the auth.navbar() helper to create your login account, there is already a change in the trunk that solves this problem (will be released soon). The new auth.navbar() will automatically add the _next variable to all links, so after clicking any navigation link, the user will be redirected back to the original page. In the meantime, you can edit auth.navbar() as follows:
import urllib navbar = auth.navbar() if not auth.is_logged_in and request.args(0) != 'login': navbar[1]['_href'] += '?_next=' +\ urllib.quote(URL(args=request.args, vars=request.vars))
source share