title: python flask dynamic dropdown list
body: <p>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</p>
  
  <p><strong>I can't use a post request as i need next to make a post request to get the user's specific details</strong>
  here's my try</p>
  
  <pre><code>
  @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)
  
  </code></pre>
  
  <p><strong>this is the main part of :DefaultAdminSelectDepartment.html</strong></p>
  
  <pre><code>    &lt;br&gt;
      &lt;form method="POST"&gt;
        &lt;label for="departments"&gt;Departments : &lt;/label&gt;
        &lt;select name="departments" id="departments"  onchange='this.form.submit()' onfocus="this.selectedIndex = -1;"&gt;
          {% for item in dept %}
          &lt;option value="{{ item.id }}"&gt;{{item.Dept_name}}&lt;/option&gt;
          {% endfor %}
        &lt;/select&gt;
        &lt;noscript&gt;&lt;input type="submit" value="Submit"&gt;&lt;/noscript&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p><strong>and this is the main part of : DefaultAdminManageUsers.html</strong></p>
  
  <pre><code> &lt;form method="PUT"&gt;
        &lt;label for="departments"&gt;Departments : &lt;/label&gt;
        &lt;select name="departments" id="departments"  onchange='this.form.submit()' onfocus="this.selectedIndex = -1;"&gt;
          {% for item in dept %}
          &lt;option value="{{ item.id }}"&gt;{{item.Dept_name}}&lt;/option&gt;
          {% endfor %}
        &lt;/select&gt;
        &lt;noscript&gt;&lt;input type="submit" value="Submit"&gt;&lt;/noscript&gt;
        &lt;/form&gt;
        &lt;form method="POST"&gt;
          &lt;label for="users"&gt;Users : &lt;/label&gt;
          &lt;select name="users" id="users"  onchange='this.form.submit()' onfocus="this.selectedIndex = -1;"&gt;
            {% for user in users %}
            &lt;option value="{{ user.id }}"&gt;{{user.name}}&lt;/option&gt;
            {% endfor %}
          &lt;/select&gt;
          &lt;noscript&gt;&lt;input type="submit" value="Submit"&gt;&lt;/noscript&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>the <strong>put</strong> 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</p>