I am working on a project using flask and I have a form in a jinja2 template where a user can enter a movie title in order to change the old title the movie had
<h1> Select a field in the movie to update </h1>
<form action = "{{url_for('execute_movie_update')}}" method = "post">
<label="update-title">Change the title</label>
<input type = "text" id="change-title" name = "new-title" required>
<button type = "submit">Submit changes</button>
</form>
How I get the new title in my flask endpoint:
@app.route('/executemovieupdate' , methods = ['GET', 'POST'])
def execute_movie_update():
if 'Email' in session and 'User' in session:
email = session['Email']
user = session['User']
if user == 'Admin':
if 'Movie' in session and 'Movie_year' in session and 'Movie_plot' in session:
movie = session['Movie']
year = session['Movie_year']
plot = session['Movie_plot']
tainia = movies.find_one({'title':movie , "year":year})
if request.method == 'POST':
new_title = request.args.get('new-title') #error happens here
new_year = request.args.get('new-year')
if new_title!=None:
print("time to update")
movies.update_one({"title":movie , "year":year} , {"$set":{"title":new_title}})
return render_template('movie-update.html' , movie = tainia)
else:
print("no title given ")
return render_template('movie-update.html' , movie = tainia)
else:
return render_template('movie-update.html' , movie = tainia)
else:
return redirect(url_for('admin.html'))
else:
return redirect(url_for('login'))
else:
return redirect(url_for('login'))
The problem is that I submit the title and send it to the flask app but I cannot enter my if statement above even if the title is submitted I would appreciate your help with guiding me to solve this simple task . Thank you in advance.