commit 0fb18bf1e89978cfd4887c15f59a29a9a7b81ec9 Author: bc759751 Date: Wed Jun 10 15:06:35 2020 +0800 test01 diff --git a/app.py b/app.py new file mode 100644 index 0000000..f857245 --- /dev/null +++ b/app.py @@ -0,0 +1,45 @@ +from flask import Flask, render_template, request, json + +app = Flask(__name__) +@app.route("/") +def index(): + return render_template("startupterrace-form.html") + + +@app.route("/datas/", methods=['GET', 'POST']) +def datas(): + print(request.form) + + if request.method == 'POST': + filename = 'data666.json' + # 讀出 JSON + with open(filename, 'r', encoding='utf-8') as file: + json_data = json.load(file) + print(json_data) + + # 整理(插入)資料 + json_data.append(request.form) + print(json_data) + + # 寫入 JSON + with open(filename, 'w', encoding='utf-8') as file: + # file.write("\n") + json.dump(json_data, file, ensure_ascii=False) + return render_template("yourdata.html") + + +@app.route("/happy/") +def happy(): + print(request) + print(type(request)) + return "開心" + + +def result(): + if request.method == 'POST': + result = request.form + return render_template("result.html", result=result) + + +if __name__ == "__main__": + app.run(debug=True) diff --git a/data666.json b/data666.json new file mode 100644 index 0000000..5427c36 --- /dev/null +++ b/data666.json @@ -0,0 +1 @@ +[{"email": "bc759751123@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}, {"email": "bc759751@gmail.com", "phone": "0910875969", "sex": "male", "where": "林口新創園 Line@"}] \ No newline at end of file diff --git a/myapp.py b/myapp.py new file mode 100644 index 0000000..561b8f2 --- /dev/null +++ b/myapp.py @@ -0,0 +1,39 @@ +from flask import Flask, g, request + +app = Flask(__name__) + + +@app.before_request +def before_request(): + print("before request started") + print(request.url) + + +@app.before_request +def before_request2(): + print("before request started 2") + print(request.url) + g.name = "SampleApp" + + +@app.after_request +def after_request(response): + print("after request finished") + print(request.url) + response.headers['key'] = 'value' + return response + + +@app.teardown_request +def teardown_request(exception): + print("teardown request") + print(request.url) + + +@app.route('/') +def index(): + return 'Hello, %s!' % g.name + + +if __name__ == '__main__': + app.run(host='0.0.0.0', debug=True) diff --git a/skysky.py b/skysky.py new file mode 100644 index 0000000..8add2fc --- /dev/null +++ b/skysky.py @@ -0,0 +1,6 @@ +import json +username = input("What is your name? ") +filename = 'username.json' +with open(filename, 'w') as f_obj: + json.dump(username, f_obj) + print("We'll remember you when you come back, " + username + "!") diff --git a/templates/gary.html b/templates/gary.html new file mode 100644 index 0000000..6748bf5 --- /dev/null +++ b/templates/gary.html @@ -0,0 +1,11 @@ + + + + + Flask教學 + + +

我的第一個Flask網站

+

Flask是一個使用Python編寫的輕量級Web應用框架。

+ + \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..7e90b3a --- /dev/null +++ b/templates/login.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} +{% block body %} +
+ Hello {{ title }}, please login by: + +
+{% endblock %} \ No newline at end of file diff --git a/templates/startupterrace-form.html b/templates/startupterrace-form.html new file mode 100644 index 0000000..1798f50 --- /dev/null +++ b/templates/startupterrace-form.html @@ -0,0 +1,112 @@ + + + + + + + Document + + + + + + +
+
+

限時活動

+

6/11-6/12

+

填完以下資料即可獲得一組免費兌換的優惠碼喔~

+

限量 50 組

+
+
+
+
+ +

我是...

+
+
+ + +
+
+ + +
+
+ +

我從何得知此活動消息

+
+ +
+ +

我的電子信箱

+
+ +
+ +

我的電話

+
+ +
+ +
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/templates/student.html b/templates/student.html new file mode 100644 index 0000000..50a3e7d --- /dev/null +++ b/templates/student.html @@ -0,0 +1,17 @@ + + + + + + Document + + +
+ 姓名 +

Physics

+

Chemistry

+

Maths

+

+
+ + \ No newline at end of file diff --git a/templates/yourdata.html b/templates/yourdata.html new file mode 100644 index 0000000..ac341e9 --- /dev/null +++ b/templates/yourdata.html @@ -0,0 +1,11 @@ + + + + + + Document + + +

感恩

+ + \ No newline at end of file