libutil.py 文件源码

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

项目:enkiWS 作者: juliettef 项目源码 文件源码
def make_local_url( locale, route_name, parameters ):
# example input: make_local_url( 'fr_FR' , 'login', { 'key1':'value1', 'key2':'value2', '_fragment':'top' })
# example output: http://www.mysite.com/login?locale=fr_FR&key1=value1&key2=value2#top
    temp_params = {} # modify a temporary dict so as not to modify parameters as this affects the jinja template
    url = ''
    for key, value in parameters.items():
        # parameters cleanup: remove parameters with blank values and UTF-8 encode the remaining values.
        if value:
            temp_params[ key ] = value.encode('utf-8')
    if locale:
        # add locale parameter to the parameters dictionnary
        # temp_params[ 'locale' ] = locale.encode('utf-8')
        url = webapp2.uri_for( 'locale-' + route_name, locale = locale.encode('utf-8'), _full = True, **temp_params )
    else:
        url = webapp2.uri_for( route_name, _full = True, **temp_params )
    return url
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号