因为刚起步,BUG很多,你筛选着看看
前端 HTML__flask 模板:<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<style type="text/css">
div.one {
border-style: solid;
border-width: 1px;
border-color: #0000ff;
margin-top: 40px;
width: 500px;
margin-left: 400px;
height: 180px
}
div.two {
border-style: solid;
border-width: 1px;
border-color: red;
margin-top: 5px;
width: 500px;
margin-left: 400px;
height: 480px
}
.one .form-line {
display: flex;
justify-content: left;
align-items:flex-start;
}
label {
display: inline-block;
width: 80px;
text-align: right;
}
.fabu {
margin-top: 15px;
margin-left: 20px;
}
#input1 {
width: 400px;
}
.neirong {
margin-top: 5px;
width: 400px;
}
button:last-child {
width: 100px;
height: 50px;
margin-left: 80px;
}
</style>
</head>
<body>
<div class="one">
<form class="form-horizontal" method="post">
<div class="form-line">
<label>用户名</label>
<input type="text" name="username" class="form-control" id="input1" value="">
</div>
<div class="form-line"><label>留言内容</label>
<textarea name="texts" class="neirong" rows="5" cols="50"></textarea>
</div>
<div class="form-line"><button type="submit" class="fabu">发布</button>
</div>
</form>
</div>
<div class="two">
{% for x in res %}
<li> {{time}} {{maohao}} {{x[1]}} {{maohao}} </li>
<li> {{x[2]}} </li>
{% endfor %}
</div>
</body>
</html>
后台:FLASK+PYTHON
from flask import Flask,request,render_template,redirect
import sqlite3 as sql
from datetime import datetime
conn=sql.connect("test.db")
c=conn.cursor()
res=list(c.execute('''select * from datas'''))
app = Flask(__name__)
maohao=":"
@app.route("/lybmain",methods=['GET','POST'])
def lybwrite():
time = datetime.now()
if request.method =='POST':
username = request.form['username']
texts=request.form['texts']
res.append(("1",username,texts))
time = datetime.now()
return render_template("lybmain.html",time=time,maohao=maohao,res=res)
@app.route("/",methods=['GET','POST'])
def login():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
|