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