BackEnd
搭建flask环境_cmd
虚拟环境;
pip install virtualenv
建立virtual文件夹(内含虚拟python);
py -3 -m venv virtual
方法2:
进入虚拟python的cmd:
virtual/Scripts/activate
搭建Flask框架_python
app.py
注意success,methods=[“POST”]
解释:
__name__得到当前py的名字——— __ main __ ;
Flask()为flask的构造函数;
from flask import Flask,render_template,request #得到email by request
app=Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
#request可得到该页面的methods
@app.route("/success",methods=["POST"]) #传入methods
def success():
#加入对邮箱的抓取
if request.method=='POST': #若按了按钮进入success
email=request.form['email_name'] #得到form["email_name"]
height=request.form["height_name"]
print(height)
return render_template("success.html")
if __name__ =='__main__':
app.debug=True
app.run(port=5001)
index.html
注意action={
{url_for(“success”)}} method=“POST”>
<!DOCTYPE html>
<html lang="en">
<title>Data Collector App</title>
<head>
<link href="../static/main.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Collecting height</h1>
<h3>Please fill entires to get population statistics on height</h3>
<form action={
{
url_for("success")}} method="POST">
<input title="Your email will be safe with us" placeholder="Enter your email address" type="email" name="email_name" required><br>
<input title="Your data will be safe with us" placeholder="Enter your Height in CM" type="number" min="50",max="300" name="height_name" required><br>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
后端数据:POSTSQL数据库
(1)建立database;
(2)进入python在database中创建table,储存height数据;
选择1:使用psycopg2;
import psy