def get_redirect_target():
    """Get URL to redirect to and ensure that it is local."""
    for target in request.values.get('next'), request.referrer:
        if target and is_local_url(target):
            return target
Get URL to redirect to and ensure that it is local.