推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
yearking
V2EX  ›  Python

如何把 js 中的数据传到 Python 中

  •  
  •   yearking · Aug 20, 2018 · 4007 views
    This topic created in 3009 days ago, the information mentioned may be changed or developed.
    10 replies  •  2018-08-23 16:20:13 +08:00
    yearking
    yearking
    OP
    Aug 20, 2018
    1
    正在学 python,如果可以,请给我一个案例学习。
    throns
    throns
    Aug 20, 2018 via Android❤️1
    2
    yamedie
    yamedie
    Aug 20, 2018
    3
    python 写一个 rest 接口供 js 调用就好了
    yearking
    yearking
    OP
    Aug 20, 2018
    4
    问题没有描述清楚,我重新描述一下。
    我在 data.js 中定义了 var huilv = document.getElementById("huilv666").value;,如何在 main.py 中获取 data.js 中的 huilv ?
    yixiugegegege
    yixiugegegege
    Aug 20, 2018
    5
    你这个问题的本质是 前端 怎么向 py 后端 传送数据
    前端一般是用 ajax
    py 后端最好用一个框架比如 tornado ,django 等 ,启动一个服务,
    伪代码:
    def main():
    if request.metod == 'POST'
    yixiugegegege
    yixiugegegege
    Aug 20, 2018❤️1
    6
    太监了,理解一下
    airdge
    airdge
    Aug 20, 2018
    7
    phantomjs
    a476286557
    a476286557
    Aug 21, 2018
    8
    前端一般 ajax 即可。可以百度 ajax 和 flask 等框架传递 json。里面有详细的例子
    aniua
    aniua
    Aug 23, 2018
    9
    你需要用随便哪个 web 框架起个 http 服务,来接收 http 请求。如 flask,最简单的情况是
    from flask import Flask, request
    app = Flask(__name__)

    @app.route('/', methods=['POST'])
    def index():
    data = request.json()
    # blabla 写你自己的逻辑然后 return

    app.run()
    aniua
    aniua
    Aug 23, 2018
    10
    页面则用 ajax 发起请求
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2435 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 97ms · UTC 04:53 · PVG 12:53 · LAX 20:53 · JFK 23:53
    ♥ Do have faith in what you're doing.