Python has a really interesting feature called function decorators. **kwargs): if g.user is None: return redirect(url_for('login', next=request.url)) return f(*args, You'll have to pass it along when sending the POST request from the login form..