我正在尝试将“#”符号解析为Flask项目中的直接url。问题是,每次请求url时,它都会打断包含#init的任何值,因为它是url编码中的一个特殊字符
localhost:9999/match/keys?source=#123&destination=#123
在flask中,我试图得到这样的论点
app.route(f'/match/keys/source=<string:start>/destination=<string:end>', methods=['GET'])
我在控制台上看到的url响应如下:
"GET /match/keys/source=' HTTP/1.0" 404 -] happens
我找到了另一个解决办法。我没有使用GET方法,而是切换到POST
在app.routes中,我发送了参数以获取_json
在《邮递员》中,我发送POST请求并发送尸体,如下所示: Postman Post request
我相信您可能不完全理解“查询字符串”在flask中是如何工作的。此url:
无法按预期工作,因为它与请求不匹配:
相反,它可能是:
这将符合:
然后,要捕获这些“查询字符串”,您需要执行以下操作:
因此,当您调用
localhost:9999/match/keys?source=%23123&destination=%23123
时,您将测试请求url中的那些“查询字符串”,如果它们是,则路由函数将执行我写了这个测试:
并使用此路由功能通过:
您可以看到,我能够在单元测试中捕获查询字符串源值
相关问题 更多 >
编程相关推荐