【问题标题】:How to modify query string in python (CGI)如何在 python (CGI) 中修改查询字符串
【发布时间】:2011-04-06 22:16:22
【问题描述】:

我正在 Python 中试验 cgi,我想知道如何修改查询字符串。

例如,如果我有一段 HTML:

<form action="/cgi-bin/text.py" method="get">
    <textarea name="stuff"></textarea>
    <button type="submit">Submit</button>
</form>

那么查询字符串可能类似于

http://www.foobar.com/cgi-bin/test.py?stuff=Some+text+here

如果我的 python 脚本返回 html,我如何将查询字符串修改为类似

http://www.foobar.com/cgi-bin/test.py?stuff=Some+text+here#anchor

让浏览器跳转到脚本返回的html文档中的适当位置?

【问题讨论】:

  • 我认为它可能必须涉及重定向。
  • 事实证明,它确实涉及重定向。感谢您为我指明正确的方向。
  • 如果您有时间,最好将您找到的解决方案作为此问题的答案,以便其他人受益:)

标签: python html cgi query-string


【解决方案1】:

尝试使用 urlparse 模块:http://docs.python.org/library/urlparse.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多