My issue is this. I can retrieve the chosenclass variable from the html text box, and the classroom of students is displayed, but after the updatepa function is called, that is after a student record has been updated, the variable is reset to the initial value of " " and so no class is displayed in the form.
I need a way of retaining the value of chosenclass. I'm thinking flask g or session might work but I'm not really sure how to implement this in my code. Or is there a better way of retaining a variable?
I have tried chosenclass = request.g.get('chosenclass') but receive the error message AttributeError: 'Request' object has no attribute 'g'
Any thoughts on how to go about this would be appreciated
Thanks
Ramone
I need a way of retaining the value of chosenclass. I'm thinking flask g or session might work but I'm not really sure how to implement this in my code. Or is there a better way of retaining a variable?
Python:
@app.route('/' , methods = ["GET", "POST"])
def Index():
chosenclass = request.values.get('chosenclass')
all_data = Data.query.filter_by(classroom=chosenclass).all()
return render_template("index.html", students = all_data)
Python:
@app.route('/updatepa', methods = ['GET', 'POST'])
def updatepa():
if request.method == 'POST':
my_data = Data.query.get(request.form.get('id'))
my_data.name = request.form['name']
my_data.studentid = request.form['studentid']
my_data.classroom = request.form['classroom']
my_data.classtime = request.form['classtime']
my_data.pacomment = request.form['pacomment']
db.session.commit()
flash("Student Updated Successfully")
return redirect(url_for('Index'))
I have tried chosenclass = request.g.get('chosenclass') but receive the error message AttributeError: 'Request' object has no attribute 'g'
Any thoughts on how to go about this would be appreciated
Thanks
Ramone
Last edited by a moderator: