title: Is it bad practice to have multiple routes per flask view function?
body: <p>So basically I have multiple <code>render_template</code> returns based on if statements, and they return different variables that my jinja2 template responds to. I believe I could break up these routes into their own functions (likewise I could break up my templates too into more than one template (for example an edit.html template instead of an <code>{% if editform %}</code> in my template)), but I like the idea of having a single view function and template for any given page. </p>
  
  <p>Before I spend more time creating the rest of my view functions, I want to make sure that what I'm doing isn't going to bite me later. </p>
  
  <p>Code below, thanks!</p>
  
  <pre><code>@app.route('/admin/users/', defaults={'id': None}, methods = ['GET'])
  @app.route('/admin/users/&lt;id&gt;', methods = ['GET'])
  @app.route('/admin/users/edit/&lt;id&gt;', methods = ['GET', 'POST'])
  @login_required
  def users(id):
      if not current_user.role == ROLE_ADMIN:
          flash('You do not have access to view this page.')
          return redirect(url_for('index'))
  
      if id:
          user = User.query.filter_by(id = id).first()
  
          if 'edit' in request.path:
              editform = UserForm()
  
              if editform.validate_on_submit():
                  user.username = editform.username.data
                  user.email = editform.email.data
                  user.role = editform.role.data
  
                  db.session.add(user)
                  db.session.commit()
  
                  return redirect('/admin/users/' + str(user.id))
  
              editform.username.data = user.username
              editform.email.data = user.email
              editform.role.data = user.role
  
              return render_template("users.html",
                  title = "Edit User",
                  user = user,
                  editform = editform)
  
          return render_template("users.html",
              title = "User",
              user = user)
  
      users = User.query.all()
  
      return render_template("users.html",
          title = 'Users',
          users = users)
  </code></pre>