prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  HTML Template rendered when page doesn't exist in API
  If a paginated API endpoint is called with a non-existant page number, a template is rendered which should never happen in case of REST APIs.
  
  ```
  http http://localhost:5000/api/v1/event/page/2
  HTTP/1.0 404 NOT FOUND
  Content-Length: 1062
  Content-Type: text/html; charset=utf-8
  Date: Sat, 21 May 2016 07:51:38 GMT
  Server: Werkzeug/0.11.7 Python/2.7.10
  
  <!DOCTYPE html>
  <html>
  <head lang="en">
      <meta charset="UTF-8">
      <title>You got 404'd</title>
      <link href="/admin/static/bootstrap/bootstrap3/css/bootstrap.min.css" rel="stylesheet">
      <link href="/static/admin/css/roboto.css" rel="stylesheet">
      <link href="/static/admin/css/material-custom.css" rel="stylesheet">
  </head>
  <body>
  <div class="container">
      <div class="row">
          <div class="col-md-push-3 col-md-6" style="margin-top: 20px;">
              <div class="jumbotron">
                  <h2 style="font-weight: 100; ">Page Not Found</h2>
                  <p class="lead">Oops, the page you're looking for does not exist.</p>
                  <p style="font-size: 14px;">
                      You may want to head back to the homepage and restart your journey.
                  </p>
                  <a href="/" class="btn btn-large btn-info" style="background-color: #3f51b5;">
                      <i class="glyphicon glyphicon-home"></i> Take Me Home
                  </a>
              </div>
          </div>
      </div>
  </div>
  </body>
  </html>
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `open_event/helpers/object_formatter.py`
  Content:
  ```
  1 """Copyright 2015 Rafal Kowalski"""
  2 from flask import jsonify
  3 
  4 from .query_filter import QueryFilter
  5 
  6 
  7 PER_PAGE = 20
  8 
  9 
  10 class ObjectFormatter(object):
  11     """Object formatter class"""
  12     @staticmethod
  13     def get_json(name, query, request, page=None):
  14         """Returns formatted json"""
  15         objects = QueryFilter(request.args, query).get_filtered_data()
  16         count = objects.count()
  17         if not page:
  18             return jsonify(
  19                 {name: [
  20                     table_object.serialize
  21                     for table_object in
  22                     objects]})
  23         else:
  24             pagination = objects.paginate(page, PER_PAGE)
  25             return jsonify({
  26                 name: [
  27                     table_object.serialize
  28                     for table_object in
  29                     pagination.items
  30                     ],
  31                 'total_pages': pagination.pages,
  32                 'page': pagination.page
  33             })
  34
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/open_event/helpers/object_formatter.py b/open_event/helpers/object_formatter.py
  --- a/open_event/helpers/object_formatter.py
  +++ b/open_event/helpers/object_formatter.py
  @@ -21,6 +21,8 @@
                       for table_object in
                       objects]})
           else:
  +            if count <= ((page-1) * PER_PAGE):  # no results possible
  +                return jsonify({})
               pagination = objects.paginate(page, PER_PAGE)
               return jsonify({
                   name: [
  
verification_info: {"golden_diff": "diff --git a/open_event/helpers/object_formatter.py b/open_event/helpers/object_formatter.py\n--- a/open_event/helpers/object_formatter.py\n+++ b/open_event/helpers/object_formatter.py\n@@ -21,6 +21,8 @@\n                     for table_object in\n                     objects]})\n         else:\n+            if count <= ((page-1) * PER_PAGE):  # no results possible\n+                return jsonify({})\n             pagination = objects.paginate(page, PER_PAGE)\n             return jsonify({\n                 name: [\n", "issue": "HTML Template rendered when page doesn't exist in API\nIf a paginated API endpoint is called with a non-existant page number, a template is rendered which should never happen in case of REST APIs.\n\n```\nhttp http://localhost:5000/api/v1/event/page/2\nHTTP/1.0 404 NOT FOUND\nContent-Length: 1062\nContent-Type: text/html; charset=utf-8\nDate: Sat, 21 May 2016 07:51:38 GMT\nServer: Werkzeug/0.11.7 Python/2.7.10\n\n<!DOCTYPE html>\n<html>\n<head lang=\"en\">\n    <meta charset=\"UTF-8\">\n    <title>You got 404'd</title>\n    <link href=\"/admin/static/bootstrap/bootstrap3/css/bootstrap.min.css\" rel=\"stylesheet\">\n    <link href=\"/static/admin/css/roboto.css\" rel=\"stylesheet\">\n    <link href=\"/static/admin/css/material-custom.css\" rel=\"stylesheet\">\n</head>\n<body>\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-md-push-3 col-md-6\" style=\"margin-top: 20px;\">\n            <div class=\"jumbotron\">\n                <h2 style=\"font-weight: 100; \">Page Not Found</h2>\n                <p class=\"lead\">Oops, the page you're looking for does not exist.</p>\n                <p style=\"font-size: 14px;\">\n                    You may want to head back to the homepage and restart your journey.\n                </p>\n                <a href=\"/\" class=\"btn btn-large btn-info\" style=\"background-color: #3f51b5;\">\n                    <i class=\"glyphicon glyphicon-home\"></i> Take Me Home\n                </a>\n            </div>\n        </div>\n    </div>\n</div>\n</body>\n</html>\n```\n\n", "before_files": [{"content": "\"\"\"Copyright 2015 Rafal Kowalski\"\"\"\nfrom flask import jsonify\n\nfrom .query_filter import QueryFilter\n\n\nPER_PAGE = 20\n\n\nclass ObjectFormatter(object):\n    \"\"\"Object formatter class\"\"\"\n    @staticmethod\n    def get_json(name, query, request, page=None):\n        \"\"\"Returns formatted json\"\"\"\n        objects = QueryFilter(request.args, query).get_filtered_data()\n        count = objects.count()\n        if not page:\n            return jsonify(\n                {name: [\n                    table_object.serialize\n                    for table_object in\n                    objects]})\n        else:\n            pagination = objects.paginate(page, PER_PAGE)\n            return jsonify({\n                name: [\n                    table_object.serialize\n                    for table_object in\n                    pagination.items\n                    ],\n                'total_pages': pagination.pages,\n                'page': pagination.page\n            })\n", "path": "open_event/helpers/object_formatter.py"}], "after_files": [{"content": "\"\"\"Copyright 2015 Rafal Kowalski\"\"\"\nfrom flask import jsonify\n\nfrom .query_filter import QueryFilter\n\n\nPER_PAGE = 20\n\n\nclass ObjectFormatter(object):\n    \"\"\"Object formatter class\"\"\"\n    @staticmethod\n    def get_json(name, query, request, page=None):\n        \"\"\"Returns formatted json\"\"\"\n        objects = QueryFilter(request.args, query).get_filtered_data()\n        count = objects.count()\n        if not page:\n            return jsonify(\n                {name: [\n                    table_object.serialize\n                    for table_object in\n                    objects]})\n        else:\n            if count <= ((page-1) * PER_PAGE):  # no results possible\n                return jsonify({})\n            pagination = objects.paginate(page, PER_PAGE)\n            return jsonify({\n                name: [\n                    table_object.serialize\n                    for table_object in\n                    pagination.items\n                    ],\n                'total_pages': pagination.pages,\n                'page': pagination.page\n            })\n", "path": "open_event/helpers/object_formatter.py"}]}