Explorar el Código

上傳檔案到 'flask/test_more_button'

fatwolf hace 3 años
padre
commit
b56ef04b19
Se han modificado 2 ficheros con 68 adiciones y 0 borrados
  1. 34 0
      flask/test_more_button/index.html
  2. 34 0
      flask/test_more_button/test.py

+ 34 - 0
flask/test_more_button/index.html

@@ -0,0 +1,34 @@
+<!doctype html>
+<html>
+
+<head>
+    <title>The jQuery Example</title>
+
+    <h2>jQuery-AJAX in FLASK. Execute function on button click</h2>  
+
+    
+</head>
+
+<body> 
+
+    
+    <pre>{{result}}</pre>
+    <pre>{{result}}</pre>
+    <pre>{{result}}</pre>
+    <form method="post" action="{{ url_for('SomeFunction') }}">
+    <input type="text" name="user">
+    <input type="submit" name="send" value="送出">
+    </form>
+
+    <form method="post" action="{{ url_for('fuck') }}">
+    <input type="text" name="axv">
+    <input type="submit" name="send" value="送出">
+    </form>
+
+    <form method="post" action="{{ url_for('check_mosquitto') }}">
+    <input type="text" name="user">
+    <input type="submit" name="send" value="送出">
+    </form>
+</body>    
+
+</html>

+ 34 - 0
flask/test_more_button/test.py

@@ -0,0 +1,34 @@
+from flask import Flask, jsonify, render_template, request
+app = Flask(__name__)
+
+
+@app.route('/',methods=['POST', 'GET'])
+def index():
+    if request.method == 'POST':
+        if request.values['send'] == '送':
+            return render_template('index.html', name=request.values['axv'])
+        elif request.values['pos'] == '送出':
+            return render_template('index.html', name=request.values['user'])
+    return render_template('index.html', name="")
+
+
+@app.route('/SomeFunction',methods=['POST', 'GET'])
+def SomeFunction():
+    if request.method == 'POST':
+        x123 = 'fuck SomeFunction'
+        print(x123)
+        return render_template('index.html',x123=x123)
+    return render_template('index.html')
+
+@app.route('/fuck',methods=['POST', 'GET'])
+def fuck():
+    if request.method == 'POST':
+        xx = 'fuck'
+        print(xx)
+        return render_template('index.html',xx=xx)
+    return render_template('index.html')
+
+
+
+if __name__ == '__main__':
+   app.run()