在html上按下按钮,Flask什么也没做

时间:2016-12-09 11:39:33

标签: python html flask request vps

我有一个带有一个按钮的网站。按下按钮时,我想使用Flask消息。

from flask import Flask
from flask import render_template
from flask import request


app = Flask(__name__)
@app.route("/")
def index():
    return render_template('index.html')

@app.route("/")
def login():
    if request.method == 'POST':
        return 'yes it works'

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

知道为什么没有发生?为什么当我按下按钮时,我没有收到“是的有效”的消息?

HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 11 - http://www.wysiwygwebbuilder.com">
<link href="{{ url_for('static', filename='css/Untitled3.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/index.css') }}" rel="stylesheet">
</head>
<body>
<input type="submit" id="Button1" name="" value="Submit" style="position:absolute;left:382px;top:298px;width:96px;height:25px;z-index:0;">
</body>
</html>

1 个答案:

答案 0 :(得分:1)

两件事

  1. 你的python中有一个重复的路由
  2. 您可能想要

    public class FieldSet extends RelativeLayout {
    
        final ViewGroup vg;
    
        public FieldSet(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            LayoutInflater.from(context).inflate(R.layout.field_set, this, true);
            vg = (ViewGroup) findViewById(R.id.field_set_content);
        }
    
        @Override
        public void addView(View child, int index, ViewGroup.LayoutParams params) {
            final int id = child.getId();
            if (id == R.id.field_set_content || id == R.id.field_set_label) {
                super.addView(child, index, params);
            }
            else {
                vg.addView(child, index, params);
            }
        }
    }
    

    你的html将你的按钮包裹在@app.route("/") def index(): return render_template('index.html') @app.route("/login", methods=['POST']) def login(): if request.method == 'POST': return 'yes it works' 元素

    <form>