title: Verbose routes in Flask
body: <p>I'm coming from a Rails background and I found my flask routes to become very messy very quickly. It seems like flask encourages you to put all of your controller logic into your route/app definition.</p>
  
  <p>So instead of</p>
  
  <pre><code>resources :users
  </code></pre>
  
  <p>and throwing the implementation into users_controller.py</p>
  
  <p>I get</p>
  
  <pre><code>@app.route("/users"), methods=["GET"]
  def list_users():
      return ..
  
  @app.route("/users/new"), methods=["GET"]
  def new_user():
      return render_template("new")
  
  @app.route("/users"), methods=["POST"]
  def create_user()
      ....
  </code></pre>
  
  <p>Then add in another 4 actions. Is this really required?</p>
  
  <p>I have tried with blueprints which seems to compare with Rails Engines, but it's not the kind of partitioning I'm looking for. How can I make my routes about my routes and not about their implementation? Do I really have to upgrade to Django?</p>
  
  <h3>Edit</h3>
  
  <p>To put it a different, perhaps clearer way: I want the methods out of my <code>app.py</code> file. And I want a higher abstraction than <code>route()</code> for defining CRUD resources. Something like</p>
  
  <pre><code>app.resources("users", controller=UsersController)
  </code></pre>
  
  <p>or better yet, have Flask resolve the controller based on the resource name.</p>
  
  <p>The UsersController will then look something like this</p>
  
  <pre><code>class UsersController:
  
      def index():
          pass
  
      def show(user_id):
          pass
  
      def new():
          pass
  
      def create():
          pass
  
      def edit(user_id):
          pass
  
      def update():
          pass
  
      def delete():
          pass
  </code></pre>