这是一个相当愚蠢的问题,但我逐步通过功能,但无法找出是什么原因造成的问题。你知道吗
我动态地向通过SQLAlchemy从db获取的对象添加了一个属性,在调用return render\u模板之前,对象被很好地追加了,除了在变量列表中的最后一个追加属性之外,其他所有的都被追加了_调查.问题他迷路了。即找到_调查.问题[0]。选项不存在(但在某一点上确实存在),但找到了_调查.问题[-1]。选择是。你知道吗
我似乎不知道发生了什么。。。我认为这可能是因为数据库对象(因为我没有提交调查,但我不打算这样做,我只是附加值,以便用正确的逻辑将其传递给视图)。你知道吗
非常感谢你的帮助,我真的被困住了。。。你知道吗
@app.route('/survey/<survey_id>', methods=['GET', 'POST'])
@login_required
def survey(survey_id):
form = UserSubmitForm()
found_survey = Survey.query.filter_by(id=survey_id).first()
if request.method == 'POST' and form.validate_on_submit():
print("input", form.answer_raw.data, form.category_list.data)
user_answer = Answer(note=found_survey.name,
answer_raw=form.answer_raw.data,
timestamp=datetime.utcnow(),
ip=request.remote_addr)
user_answer.user_id = g.user.id
user_answer.survey_id = survey_id
# other processing omitted
db.session.add(user_answer)
elif request.method != "POST":
for q in found_survey.questions:
q.choices = []
text_list = q.choice_text_string.split(',')
value_list = q.choice_value_string.split(',')
for i, text in enumerate(text_list):
q.choices.append((text, value_list[i]))
return render_template('survey.html',
form=form,
survey=found_survey,
is_editing=False)
这样做会不会更简单:
相关问题 更多 >
编程相关推荐