【问题标题】:Tornado Escape Pound # character龙卷风逃生磅#字符
【发布时间】:2016-11-25 04:19:13
【问题描述】:

我正在编写一个处理文本及其属性的程序/服务。 本地主机:8000/title?img=img_url.jpg&text_color=#FF0000

在我的处理程序中,我有类似的东西:

application = tornado.web.Application([
(r"/title_overlay", MainHandler),
    ])

class MainHandler(tornado.web.RequestHandler):
    def check_origin(self, origin):
         return True

    def get(self):
        image_url = self.get_argument("img", None, True)
        image_local_file = 'image' + "_" + image_url.split('/')[-1]
        urllib.urlretrieve(image_url, image_local_file)
        text_color = self.get_argument('text_color', '', True)
    .....
    ..... 
    .....

我无法获取 text_color 值,即#FF0000。提取 imgurl 有效,但不能提取 text_color。 这是否与# 字符有关。 ?

【问题讨论】:

    标签: python python-2.7 web-services url tornado


    【解决方案1】:

    是的,这是因为“#”之后的部分称为fragment identifier,浏览器在获取 URL 时甚至不会将其发送到服务器。为了在您的 URL 中编码颜色,您必须省略“#”字符,或者对其进行 URL 编码:

    text_color=%23FF0000

    【讨论】:

    • 有什么办法可以得到吗?
    • 浏览器在获取 URL 时甚至不会将片段发送到服务器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多