I want to fetch data from a database using flask-alchemy, based on a string value I have passed from another screen. But here's the problem, I get a 400 error
for my password and I don't know what I'm doing wrong.
Here is the function that fetches my data:
def userToEdit(userVar):
with session_scope() as s:
userVname = s.query(tabledef.User).filter(tabledef.User.username==userVar).first()
return(userVname)
Here is the function that process with my template:
# -------- Edit Users ---------------------------------------------------------- #
@app.route('/edituser/<string:userVar>', methods=['GET', 'POST'])
def edituser(userVar):
userV = helpers.userToEdit(userVar)
if session.get('logged_in'):
if request.method == 'POST':
password = request.form['password']
if password != "":
password = helpers.hash_password(password)
email = request.form['email']
helpers.change_user(password=password, email=email)
return json.dumps({'status': 'Saved'})
else:
password = helpers.fetch_usernames.password
user = helpers.userToEdit(userVar)
pagename = "Edit User"
roles = ['Test1', 'Test2', 'Test3']
mobile_roles = ['test1', 'test2', 'test3']
states = ['Active', 'Non-active']
return render_template('edituser.html', user=user, pagename=pagename, roles=roles, states=states, mobile_roles=mobile_roles)
return redirect(url_for('login'))
Here is the part of my template which should be populated:
<div class="field">
<p class="control has-icons-left">
<input id="settings-user" class="input is-success" type="text" placeholder="{{user.username}}" readonly="readonly">
<span class="icon is-small is-left">
<i class="fa fa-user"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input id="settings-mail" class="input is-success" type="text" placeholder="{{user.email}}">
<span class="icon is-small is-left">
<i class="fa fa-envelope"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input id="settings-pass" class="input" type="password" placeholder="•••••">
<span class="icon is-small is-left">
<i class="fa fa-lock"></i>
</span>
</p>
</div>
and in case you ask the error is the following message
werkzeug.exceptions.HTTPException.wrap..newcls: 400 Bad Request: KeyError: 'password'
Now that I got everything out of the way, is there a way to fix that? Because I have no idea where to begin.