Flask请求用户输入的示例网页不执行任何操作



我试图学习如何在Flask中编码,并正在构建一个接受用户输入的小型门户(用户可以在各种复选框中进行选择(。根据输入,我试图通过excel文件显示所选列。以下是我迄今为止所做的工作,我不确定如何推进这一进程。

@app.route('/index', methods=['GET','POST'])
def user_input():
form = SampleForm()
if form.validate_on_submit():
Username = form.username_field.data
Age = form.age_field.data
output = user_input(Username,Age)
return render_template('index', form=form)

我已经通过阅读各种博客和帖子构建了上述代码,但这并没有起到任何作用。有人能告诉我上面的示例代码哪里出了问题吗。感谢

分类.py

class test(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(100), nullable=False)
age = db.Column(db.String(100), nullable=False)

Python函数:

def function(*field_names):
cursor = conn.cursor()
dwh_cursor.execute('select {} from enrolments'.format(', '.join(str(field) for field in field_names)))
print(field_names)
output_file = dwh_cursor.fetchall()

这有帮助吗?可能需要一些调整来满足您的需求。

@app.route('/index', methods=['GET','POST'])
def user_input():
form = SampleForm()
if form.validate_on_submit():
newform = User(
username = form.username_field.data,
age = form.age_field.data,
)
db.session.add(newform)
db.session.commit()
return redirect(url_for('user_input'))
return render_template('user_input', form = form)

最新更新