\n\n**/\nwinform.show();\nwin.loopMessage();", "datePublished": "2021-03-19T02:14:08Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/g00001", "@type": "Person", "name": "g00001"}}, {"text": "@g00001\n@SenLief\n@zzzmh\n谢谢, 昨晚用\n@shyling 推荐的这个封装很轻易的实现了,直接 put_text return 结果,导一个输入,一个输出模块就可以。太适合傻瓜了", "datePublished": "2021-03-19T02:57:37Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/maloneleo88", "@type": "Person", "name": "maloneleo88"}}], "interactionStatistic": [{"userInteractionCount": 3817, "@type": "InteractionCounter", "interactionType": "https://schema.org/ViewAction"}, {"userInteractionCount": 18, "@type": "InteractionCounter", "interactionType": "https://schema.org/ReplyAction"}], "text": "我现在有的:\n1.html 页面:form 字符串 提交\n2.python 脚本:只有一个功能,获取字符串\"1554***\"拿去自动处理,然后 print 结果。\n有什么最简单的方法将他们做成交互的呢?提交-然后出结果。 不会 flask.django 。\n看了一眼教程,懵了,最后还都是搭建 blog,我用不到呀。 我只想通过网页重复提交来重复处罚 python 脚本运行得到结果,有什么极简的方法吗? ε=(´ο`*)))", "datePublished": "2021-03-18T11:10:33Z", "commentCount": 18, "mainEntityOfPage": "https://www.v2ex.com/t/762946", "author": {"url": "https://www.v2ex.com/member/maloneleo88", "@type": "Person", "name": "maloneleo88"}, "headline": "怎样用一个静态 HTML 跟 Python 程序交互呢?", "url": "https://www.v2ex.com/t/762946", "isPartOf": {"url": "https://www.v2ex.com/go/python", "@type": "WebPage", "name": "Python"}, "@context": "https://schema.org", "@type": "DiscussionForumPosting"}
1
kyokuheishin 2021 年 3 月 18 日
还是用 flask 写个后端获取表单内容吧,我寻思也不是很难
|
2
Cooky 2021 年 3 月 18 日 via Android
都塞同一页面里呗
|
3
maloneleo88 OP @kyokuheishin 对我来说很难呀,有没有直奔主题的文章,一小时速成那种,老兄。
|
4
maloneleo88 OP @Cooky 塞哪个页面里?
我是想 html 输入------python 获取执行程序----------返回到 html 显示 python 不能扔 html 里跑呀,html 也扔不进 py 里。 咋弄?? |
5
junan0708 2021 年 3 月 18 日
python 自带的 http server ?
|
6
Dockerfile 2021 年 3 月 18 日
flask 或 fastapi 很快的
|
7
no1xsyzy 2021 年 3 月 18 日
flask 十分钟速成。就看 flask 官方文档的 Quickstart - A Minimal Application 就行了。
或者 FastAPI 其实 Python 能扔 HTML 里跑,WebAssembly |
8
shyling 2021 年 3 月 18 日 以前在 v2 上看到过一个人推自己的项目,类似于把 print(input('xxxx?'))转换成网页的形式,应该很适合你。(但忘了叫啥
|
9
shyling 2021 年 3 月 18 日
|
10
cz5424 2021 年 3 月 18 日 via iPhone
数据处理不复杂可以用 js 写一下
|
11
natsji 2021 年 3 月 18 日 via Android
输出成 json
|
12
dsg001 2021 年 3 月 18 日
这就别用 html 了
直接 txt 文档,python 监控文件是否修改,然后获取最后字符串进行处理 |
13
maloneleo88 OP @shyling 正在看,正是我想要的, !!! Nb
|
14
madpecker009 2021 年 3 月 19 日
为什么不考虑 flask?
|
15
zzzmh 2021 年 3 月 19 日
java 的逻辑是,写成接口,最简单的就是 servlet,请求接口返回字符串。前端用 xmlhttprequest 异步获取数据渲染到页面。。。python 不懂
|
16
SenLief 2021 年 3 月 19 日
如果要求很简单并且不要求性能什么的,可以不用框架,而是用自带的 http.server 模块,自定义一个继承 http.sever.BaseHTTPRequestHandlerl 类,里面实现一个 do_POST 方法就可以了。
|
17
g00001 2021 年 3 月 19 日
有个方案是直接嵌入 WebView
https://github.com/webview/webview 里面有 python 的封装。 如果是 Windows,可以用 aardio 嵌入 Python 和 WebView,WebView 可以直接调用 aardio 函数,aardio 函数可以直接调用 Python 函数,也就实现了 Javascript 间接调用 Python 函数。一个简单的例子: import win.ui; var winform = win.form(text="web.view") import web.view; var wb = web.view(winform); import py; var pyCode = /** def testPy(): return "测试 test" **/ py.exec( pyCode ) wb.external = { testPy = function() return tostring( py.main.testPy() ); } wb.html = /** <html><head> <script type="text/javascript"> aardio.testPy().then( v=>document.write(v) ) </script> </head> **/ winform.show(); win.loopMessage(); |
18
maloneleo88 OP |