I strongly suggest using redirect as David Wahler suggested. A note, Mozilla type browsers don't do an excellent job sending referer. You can't really trust that header anymore. If you want to go back after login, either:
(1) Render the login page INSTEAD of the normal content at the same url. Form submission would go back to the same page not requiring a login; plus, you could pick up the URL and paramters on the login page. (2) Have the page requiring login redirect with extra parameters that describe the page URL and the parameters needed to access it properly. HOWEVER, you need to be careful that you don't allow any old URL there, because someone else could have your logged in user redirect to their site. -- http://mail.python.org/mailman/listinfo/python-list