2017-09-24 7 views
-1

私はウェブサイトのフォームからpostgresqlデータベースに情報を追加しようとしています。"[none]"の値がpostgresqlに追加されます

 <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

from flask import Flask, render_template, request 
from flask.ext.sqlalchemy import SQLAlchemy 


app = Flask(__name__) 
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:[email protected]: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 tamplateです: はここに私のPythonスクリプトです!

答えて

2

あなたのinitメソッドはself.heigth_で、self.height_ではありません。

関連する問題