我正在尝试从网站表单添加信息到postgresql数据库,当我按下提交按钮时,电子邮件值正确写入数据库但高度值等于[null]? 这是我的python脚本:
from flask import Flask, render_template, request
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres123@localhost:5433/height_collector'
db = SQLAlchemy(app)
class Data(db.Model):
__tablename__ = "data"
id = db.Column(db.Integer, primary_key=True)
email_ = db.Column(db.String(120), unique=True)
height_ = db.Column(db.Integer)
def __init__(self, email_, height_):
self.email_ = email_
self.heigth_ = height_
@app.route("/")
def index():
return render_template("index.html")
@app.route("/success", methods=['post'])
def success():
if request.method == 'POST':
email = request.form["email_name"]
height = request.form["height_name"]
print(email, height)
try:
data = Data(email, height)
db.session.add(data)
db.session.commit()
except:
print('FILE')
return render_template("success.html")
if __name__ == '__main__':
app.debug = True
app.run()
这是我的html模板:
<form action="{{url_for('success')}}" method = "POST">
<input title="Yor email will be safe with us" placeholder="Enter your email address" type="email" name="email_name" required><br>
<input title="Yor data will be safe with us" placeholder="Enter your height in cm" type="number" name="height_name" min="50" max="300" required><br>
<button type="submit">Submit</button>
</form>
</div>
我的database!
答案 0 :(得分:2)
您的init方法设置.ts file :
ngOnInit():void {
this.items.push("temp Name")
let __this = this
this._userService.getAll(1).subscribe(res => {
res.users.forEach(function (a,b) {
__this.items.push(a)
})
console.log(__this.items)
})
}
,而不是<input type="text" [mention]="items" >
。