我想解析包含GET
(例如:#
)的#HelloThere
数据。我遇到错误了
$ curl http://127.0.0.1:5000/#Hello
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/<code>', methods=['GET'])
def convert(code):
print code
return json.dumps({"results": code}), 200
if __name__ == '__main__':
app.run()
我如何接受包含GET
的{{1}}数据?
我还尝试了#
并访问request.args.get('code')
,但仍然遇到相同的错误
答案 0 :(得分:0)
它被解释为fragment identifier。
如果必须在URL中传递#字符作为数据,请尝试将urlencoding的#字符改为%23
curl http://127.0.0.1:5000/%23Hello
这里有更多复杂性,您可以在以下SO答案中找到: Python - Get URL fragment identifier with Flask