utility_tags.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Django-Web-Development-with-Python 作者: PacktPublishing 项目源码 文件源码
def remove_from_query(context, *args, **kwargs):
    """ Renders a link with modified current query parameters """
    query_params = []
    # go through current query params..
    for key, value_list in context["request"].GET._iterlists():
        # skip keys mentioned in the args
        if not key in args:
            for value in value_list:
                # skip key-value pairs mentioned in kwargs
                if not (key in kwargs and unicode(value) == unicode(kwargs[key])):
                    query_params.append((key, value))
    # empty values will be removed
    query_string = context["request"].path
    if len(query_params):
        query_string = "?%s" % urllib.urlencode([
            (key, force_str(value)) for (key, value) in query_params if value
        ]).replace("&", "&")
    return query_string
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号