我目前在一个简单的超市名单工作,你有2个文本输入,他们问的产品和价格。 Image of the program without Price Textfield
所以当我要求这两个数据输入时,它在我的超级路由中给了我一个错误,那就是验证数据的错误。你知道吗
@app.route('/super', methods=['POST'])
def add_super():
content = request.form['content']
#precio = request.form['precio']
if not request.form['content'] or not request.form['precio']:
flash('Debes ingresar un texto')
return redirect('/')
super = Super(content)
#super = Super(precio)
db.session.add(super)
db.session.commit()
flash('Registro guardado con exito!')
return redirect('/')
在这里,我添加了从数据库请求数据的价格,这样我就可以调用它并在以后显示它,但这就是我得到错误的地方。你知道吗
我的数据库是这样设置的:
class Super(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text)
precio = db.Column(db.Integer)
listo = db.Column(db.Boolean, default=False)
def __init__(self, content,precio):
self.content = content
self.precio = precio
self.listo = False
def __repr__(self):
return '<Content %s>' % self.content
# def __repr__(self):
# return '<Precio %s>' % self.precio
db.create_all()
您的
Super
在其__init__
中接受2个参数,但只提供1个参数。你知道吗例如,如果我们在解释器中定义:
然后我们尝试只使用一个参数创建一个实例:
当你这样做时,可能会发生这样的情况:
但是,如果我们提供两个参数:
所以您需要创建带有两个参数的
Super
实例,就像您可能想要的那样:推测一下,你想要的可能是这样的:
相关问题 更多 >
编程相关推荐