How to get parameters in URL #28
Answered
by
wang0618
ZHANGGONGQUAN
asked this question in
Q&A
-
默认启动的是 tornado server 。
|
Beta Was this translation helpful? Give feedback.
Answered by
wang0618
Feb 22, 2021
Replies: 1 comment
-
可以使用 import pywebio
import urllib.parse
def main():
# 方法一:直接在浏览器上计算URL query字典
# 参见: https://stackoverflow.com/questions/8648892/how-to-convert-url-parameters-to-a-javascript-object
query = pywebio.session.eval_js("Object.fromEntries(new URLSearchParams(window.location.search))")
pywebio.output.put_code(query)
# 方法二:获取浏览器地址,使用python解析URL query
search = pywebio.session.eval_js("window.location.search")
query = dict(urllib.parse.parse_qsl(search.lstrip('?')))
pywebio.output.put_code(query)
pywebio.start_server(main, port=8080) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
wang0618
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以使用
pywebio.session.eval_js
函数来在浏览器上执行js获取URL参数,具体实现可参考: