test01
commit
0fb18bf1e8
@ -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)
|
@ -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@"}]
|
@ -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)
|
@ -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 + "!")
|
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Flask教學</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>我的第一個Flask網站</h1>
|
||||
<p> Flask是一個使用Python編寫的輕量級Web應用框架。</p>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
<form name="login" action="/login" method="post">
|
||||
Hello {{ title }}, please login by:
|
||||
<input type="text" name="user" />
|
||||
</form>
|
||||
{% endblock %}
|
@ -0,0 +1,112 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<!-- CSS only -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
|
||||
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
||||
<style>
|
||||
body {
|
||||
font-family: 微軟正黑體, "Microsoft JhengHei";
|
||||
}
|
||||
|
||||
.jumbotron {
|
||||
background-image: url(https://images.unsplash.com/photo-1531062916849-ac6624741870?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80);
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
input.form-check-input[type="radio"] {
|
||||
transform: scale(1.5);
|
||||
}
|
||||
|
||||
#activity {
|
||||
margin: auto;
|
||||
border-radius: 5px;
|
||||
background: rgba(255, 255, 255, .8);
|
||||
box-shadow: 3px 3px 6px 3px rgba(0, 0, 0, .3);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#activity::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
filter: blur(20px);
|
||||
z-index: -1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="jumbotron jumbotron-fluid">
|
||||
<div class="container py-4" id="activity">
|
||||
<h1 class="display-4">限時活動</h1>
|
||||
<h1>6/11-6/12</h1>
|
||||
<p class="h4">填完以下資料即可獲得一組免費兌換的優惠碼喔~</p>
|
||||
<p class="lead">限量 50 組</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container my-4">
|
||||
<form action="/datas/" method="POST">
|
||||
<!-- 性別 -->
|
||||
<h4>我是...</h4>
|
||||
<div class="d-flex">
|
||||
<div class="form-check mx-3">
|
||||
<input class="form-check-input" type="radio" name="sex" id="sexRadios1" value="male" checked>
|
||||
<label class="form-check-label" for="sexRadios1">
|
||||
男生
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check mr-3">
|
||||
<input class="form-check-input" type="radio" name="sex" id="sexRadios2" value="female">
|
||||
<label class="form-check-label" for="sexRadios2">
|
||||
女生
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4 pb-2">我從何得知此活動消息</h4>
|
||||
<div class="d-flex">
|
||||
<select class="form-control" name="where">
|
||||
<option>林口新創園 Line@</option>
|
||||
<option>林口新創園 FB 專頁</option>
|
||||
<option value="friend">朋友帶我來的~</option>
|
||||
<option value="other">其他...</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4 pb-2">我的電子信箱</h4>
|
||||
<div class="d-flex">
|
||||
<input type="email" class="form-control" id="exampleInputEmail1" name="email">
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4 pb-2">我的電話</h4>
|
||||
<div class="d-flex">
|
||||
<input type="tel" class="form-control" id="phone" name="phone" pattern="[0-9]{10}">
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<input class="btn btn-info" type="submit" value="我填完了" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<footer class="bg-dark">
|
||||
<!-- Footer Elements -->
|
||||
<div class="container">
|
||||
</div>
|
||||
|
||||
<!-- Copyright -->
|
||||
<div class="text-light text-center py-3">© 2020 Copyright: AIWill Lab Co.Ltd.</a></div>
|
||||
</footer>
|
||||
|
||||
</html>
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action = " /datas/"; method = "POST">
|
||||
<em>姓名</em> <input type = "text" name = "Name" />
|
||||
<p>Physics</p> <input type = "text" name = "Physics" />
|
||||
<p>Chemistry</p> <input type = "text" name = "chemistry" />
|
||||
<p>Maths</p> <input type ="text" name = "Mathematics" />
|
||||
<p><input type = "submit" value = "submit" /></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<P>感恩</P>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue