code: def redirect(endpoint, **kw):
      _endpoint = None
      if isinstance(endpoint, six.string_types):
          _endpoint = endpoint
          if "/" in endpoint:
              return f_redirect(endpoint)
          else:
              for r in Mocha._app.url_map.iter_rules():
                  _endpoint = endpoint
                  if 'GET' in r.methods and endpoint in r.endpoint:
                      _endpoint = r.endpoint
                      break
      else:
          if isinstance(endpoint, Mocha):
              fn = sys._getframe().f_back.f_code.co_name
              endpoint = getattr(endpoint, fn)
          if is_method(endpoint):
              _endpoint = _get_action_endpoint(endpoint)
              if not _endpoint:
                  _endpoint = _build_endpoint_route_name(endpoint)
      if _endpoint:
          return f_redirect(url_for(_endpoint, **kw))
      else:
          raise exceptions.MochaError("Invalid endpoint")