i have a flask app at which i want a page to open with two dropdown lists the first is for the department and the second is for the user i want to dynamically change user whenever i change the department in the same page
I can't use a post request as i need next to make a post request to get the user's specific details here's my try
@app.route('/ITMODE/Users/', methods=['GET', 'POST'])
@login_required
def UserModifier():
if Session.get('user_id') is None or Session['dept_id']!=1:
return redirect(url_for('login'))
else:
if request.method == 'GET':
departments= session.query(Department)
#UserRequests= session.query(Requests).order_by(desc(Requests.Record_Created)).all()
return render_template('DefaultAdminSelectDepartment.html', title='Users' ,dept=departments)
else:
department_id = request.form.get('departments')
Session['department_id']=department_id
return redirect(url_for('UserModifierDept'))
@app.route('/ITMODE/Users/departments/', methods=['GET', 'POST'])
@login_required
def UserModifierDept():
if Session.get('user_id') is None or Session['dept_id']!=1:
return redirect(url_for('login'))
else:
if request.method == 'GET':
department = Session['department_id']
departments= session.query(Department)
Users=session.query(User.name).filter(User.dept_id==department).order_by(User.name)
return render_template('DefaultAdminManageUsers.html', title='Users' ,users=Users,dept=departments)
this is the main part of :DefaultAdminSelectDepartment.html
<br>
<form method="POST">
<label for="departments">Departments : </label>
<select name="departments" id="departments" onchange='this.form.submit()' onfocus="this.selectedIndex = -1;">
{% for item in dept %}
<option value="{{ item.id }}">{{item.Dept_name}}</option>
{% endfor %}
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
and this is the main part of : DefaultAdminManageUsers.html
<form method="PUT">
<label for="departments">Departments : </label>
<select name="departments" id="departments" onchange='this.form.submit()' onfocus="this.selectedIndex = -1;">
{% for item in dept %}
<option value="{{ item.id }}">{{item.Dept_name}}</option>
{% endfor %}
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
<form method="POST">
<label for="users">Users : </label>
<select name="users" id="users" onchange='this.form.submit()' onfocus="this.selectedIndex = -1;">
{% for user in users %}
<option value="{{ user.id }}">{{user.name}}</option>
{% endfor %}
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
the put request part is a failed try the main problem is handling two post requests from same html template or somehow make the dropdowns dynamic as if the department changes the users in the other dropdown are changed