(self, urlname, kwargs=None, request=None, absolute=False)
return baseurl + location
构建url
构建url
构建url
def build_url(self, urlname, kwargs=None, request=None, absolute=False):
        """构建url"""
        kwargs = kwargs or dict()
        kwargs["appname"] = self.name
        location = reverse("wechat_django:{0}".format(urlname), kwargs=kwargs)
        if not absolute:
            return location

        if request and not self.site_host:
            baseurl = "{}://{}".format(
                "https" if self.site_https else request.scheme,
                request.get_host())
        else:
            protocol = "https://" if self.site_https else "http://"
            if self.site_host:
                host = self.site_host
            else:
                allowed_hosts = settings.settings.ALLOWED_HOSTS
                if not allowed_hosts:
                    raise RuntimeError("You need setup a WECHAT_SITE_HOST "
                                       "when build absolute url.")
                host = allowed_hosts[0]
            baseurl = protocol + host
        return baseurl + location
def build_url ( self , urlname , kwargs = None , request = None , absolute = False ) : kwargs = kwargs or dict ( ) kwargs [ "appname" ] = self . name location = reverse ( "wechat_django:{0}" . format ( urlname ) , kwargs = kwargs ) if not absolute : return location if request and not self . site_host : baseurl = "{}://{}" . format ( "https" if self . site_https else request . scheme , request . get_host ( ) ) else : protocol = "https://" if self . site_https else "http://" if self . site_host : host = self . site_host else : allowed_hosts = settings . settings . ALLOWED_HOSTS if not allowed_hosts : raise RuntimeError ( "You need setup a WECHAT_SITE_HOST " "when build absolute url." ) host = allowed_hosts [ 0 ] baseurl = protocol + host return baseurl + location