我在編碼時遇到了一些問題。我必須在Python論壇中添加一個問題。在數據庫中添加新對象後,代碼僅打印舊對象,而不打印新對象,即使在數據庫中添加了對象。 只有當我再次運行時纔會打印新對象。查詢python燒瓶後更新頁面
@app.route('/question/<topic_id>', methods=['GET', 'POST'])
def newquestion(topic_id):
username = 'elena27'
question_ = request.form['question']
new_question = applicativo.newQuestion(username, question_, topic_id)
db.session.add(new_question)
db.session.commit()
db.session.remove()
return render_template('newquestion.html')
這裏是applicativo.py:
def countQuestion():
number=int(session.query(Question).order_by('-id').first().id)
return number+1
def newQuestion(username, question, topic):
id = countQuestion()
date = datetime.now()
question = Question(id, topic, username, question, date)
return question
question.html:
<form method="POST" enctype="multipart/form-data" action={{ url_for('newquestion', topic_id=topic_id) }}>
<p>
{{ wtf.quick_form(form) }}
</p>
</form>
newquestion.html頁只是一個靜態頁面。
感謝您的幫助!
你應該不會被傳遞所有的對render_template()方法的問題? –
你使用的是什麼rdbms? – Busturdust