怎样用python的falsk库写几行代码,让程序的"def index():"中渲染上″index.html",再到"def login():"中显示“已注册”并将index.html的post表単中三个值:"username"、"phoneid"、"password"写入文件?
python代码(有错,希望指出)
#python mian.py
from flask import Falsk,render_template,requst
app = Falsk(__name__)
f = open("注册信息.txt","a")
@app.route("/")
def index():
return render_template("index.html")
@app.route("/login",methods=["POST"])
def login():
name = request.values.get("username")
id = request.values.get("phoneid")
pd = request.values.get("password")
fn = "用户名:" + name + "\n"
fn += "手机号:" + id + "\n"
fn += "密码:" + pd + "\n\n"
f.write(fn)
f.close()
app.run()
html代码
#html index.html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>注册</h1>
<h2>信息记录</h2>
<form method ="POST" action ="/login">
请输入你的用户名(Username)<input type ="text" name ="username" placeholder ="input your user"><br />
请输入你的手机号(Phone)<input type ="text" name ="phoneid" placeholder ="input your phone"><br />
请设置密码(Password)<input type= "password" name ="password" placeholder ="input your password"><br />
<input type ="submit" name ="submit">
</form>
</body>
</html>