def get_redirect_target(self, invalid_targets=()):
        check_target = self.values.get('_redirect_target') or \
                       self.values.get('next') or \
                       self.referrer

        # if there is no information in either the form data
        # or the wsgi environment about a jump target we have
        # to use the target url
        if not check_target:
            return

        # otherwise drop the leading slash
        check_target = check_target.lstrip('/')

        root_url = self.url_root
        root_parts = urlparse(root_url)

        check_parts = urlparse(urljoin(root_url, check_target))
        check_query = url_decode(check_parts[4])

        def url_equals(to_check):
            if to_check[:4] != check_parts[:4]:
                return False
            args = url_decode(to_check[4])
            for key, value in args.iteritems():
                if check_query.get(key) != value:
                    return False
            return True

        # if the jump target is on a different server we probably have
        # a security problem and better try to use the target url.
        # except the host is whitelisted in the config
        if root_parts[:2] != check_parts[:2]:
            host = check_parts[1].split(':', 1)[0]
            for rule in settings.ALLOWED_REDIRECTS:
                if fnmatch(host, rule):
                    break
            else:
                return

        # if the jump url is the same url as the current url we've had
        # a bad redirect before and use the target url to not create a
        # infinite redirect.
        if url_equals(urlparse(self.url)):
            return

        # if the `check_target` is one of the invalid targets we also
        # fall back.
        for invalid in invalid_targets:
            if url_equals(urlparse(urljoin(root_url, invalid))):
                return

        return check_target
Makes sure that the host exists.
dataset/ETHPy150Open mitsuhiko/solace/solace/application.py/Request.get_redirect_target--crossover with--dataset/ETHPy150Open nii-cloud/dodai-compute/nova/api/openstack/contrib/hosts.py/check_host