在HTML网页中运行python方法 [英] Run python method in HTML web page

查看:530
本文介绍了在HTML网页中运行python方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的HTML页面。该网页正在Flask上运行。我想要做的是当用户按下按钮时,我想调用Python方法。

main.py

  from flask import url_for,Flask,render_template 
$ b $ app = Flask(__ name__)

@ app.route('/')
def hello_world():
return render_template('tour。 (')

if __name__ =='__main__':
app.run(debug = True)

def first():
global todayDate
parseWemake(* Wemake.wemakeData())
parseCoupang(* Coupang.coupangData())
parseTmon(* Tmon.tmonData())



tour.html

 <按钮>点击< ; /按钮> 

我现在已经迷失在这里。所有我想要做的就是调用first()方法点击html上的那个按钮。



预先感谢。



你需要的是一个html表单或ajax请求。


I have a HTML page with a button. This web page is running on Flask. What I want to do is when the user press a button, I want to invoke Python method.

main.py

from flask import url_for, Flask, render_template

app = Flask(__name__)

@app.route('/')
def hello_world():
    return render_template('tour.html')

if __name__ == '__main__':
    app.run(debug=True)

def first():
    global todayDate
    parseWemake(*Wemake.wemakeData())
    parseCoupang(*Coupang.coupangData())
    parseTmon(*Tmon.tmonData())

tour.html

<button>Click</button>

I am now lost here. All I want to do is invoke first() method on click that button on html.

Thanks in advance.

解决方案

this can not be done.

because the 'click' happend in browser, but 'first' run on your server.

what you need is a html form or ajax request.

这篇关于在HTML网页中运行python方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆