title: I'm having trouble querying data from mongodb and rendering to Flask
body: <p>I have data in a MongoDB that I know exists, as I can query externally to my Flask App.  </p>
  
  <p>Query:</p>
  
  <pre><code>from pymongo import MongoClient
  import pprint
  client = MongoClient()
  db = client.reqdata
  
  cursor = db.req_data.find()
  
  for document in cursor:
      pprint.pprint(document)
  </code></pre>
  
  <p>Sample Result</p>
  
  <pre><code>{'_id': ObjectId('5a0f3abf2d6a8810fbc8e352'),
   'req': {'HiringManagerEmailId': 'Fred.Smith@company.com',
           'HiringManagerEmployeeId': 353585,
           'HiringManagerName': 'Fred Smith',
           'HiringManagerSystemId': 146472,
           'HotJob': 'No',
           'JobDescription': 'You will collaborate with colleagues from '
                             'North America and/or The Company '
                             'on national and international '
                             'client projects.&lt;br&gt; &lt;br&gt;Together with our '
                             'clients, you will develop superior IT concepts '
                             'and architecture solutions as well as support '
                             'technical implementations actively and on site, '
                             'applying your sound technical know-how, your '
                             'understanding of business contexts, and your '
                             'analytical and conceptual '
                             'skills.&lt;br&gt;&lt;br&gt;Company provides technology '
                             'consulting services to clients on the following '
                             'topics:&lt;br&gt; &lt;ul dir="ltr"&gt;&lt;li&gt; Management of '
                             'large-scale projects&lt;/li&gt;&lt;li&gt; Restructuring of '
                             'IT processes and organization&lt;/li&gt;&lt;li&gt; '
                             'Functional and technical support of mergers and '
                             'acquisitions&lt;/li&gt;&lt;li&gt; Analysis of IT and '
                             'software architecture weaknesses&lt;/li&gt;&lt;li&gt; '
                             'Specification and implementation of IT '
                             'architectures&lt;/li&gt;&lt;li&gt; Product evaluation, such '
                             'as core systems&lt;/li&gt;&lt;li&gt; Technical concept '
                             'development and design of software '
                             'solutions&lt;/li&gt;&lt;li&gt; Quality assurance for IT '
                             'implementation&lt;/li&gt;&lt;li&gt; Design and '
                             'implementation of feasibility studies&lt;/li&gt;&lt;li&gt; '
                             'Load and performance tests&lt;/li&gt;&lt;/ul&gt;',
           'JobDetailLink': 'https://someurl.foo.com/',
           'LastUpdated': '16-Nov-2017',
           'Question': ['Senior Consultant',
                        'Core Technology',
                        'North America',
                        'United States',
                        'New York',
                        'Full time',
                        '5390BR'],
           'RecruiterEmailId': 'Fred.Smith@company.com',
           'RecruiterEmployeeId': 353585,
           'RecruiterName': 'Fred Smith',
           'RecruiterSystemId': 146472},
   'timestamp': '2017-17-17 14:38:37'}
  </code></pre>
  
  <p>When I try to insert same code into my Flask App, I can get an accurate count of the documents which renders to the ~/index page, but can't seem to get data to render to the ~/mongoreqs page.</p>
  
  <p>Flask Code</p>
  
  <pre><code>from flask import Flask, render_template,request,redirect,url_for # For flask implementation
  from pymongo import MongoClient # Database connector
  from bson.objectid import ObjectId # For ObjectId to work
  
  client = MongoClient()    #Configure the connection to the database
  db = client.reqdata    #Select the database
  ##reqs = db.req_data.find()
  
  app = Flask(__name__)
  title = "Req Search with Flask"
  heading = "Req Search"
  
  
  
  @app.route('/')
  @app.route('/index')
  
  def index():
  ##    reqdb = db.req_data
      reqcount = db.req_data.count()
      return render_template('index.html',
                            title='Home',
                             reqcount = reqcount)
  
  @app.route('/mongoreqs', methods=['GET'])
  def mongo_reqs():
  ##    reqdb = db.req_data #Select the collection
  ##    client = MongoClient()    #Configure the connection to the database
  ##    db = client.reqdata 
      reqs = db.req_data.find({})
      return render_template('mongoreqs.html',
                             title="Reqs in Mongo DB",
                             reqs=reqs)
  
  
  if __name__ == "__main__":
      app.run(debug=True)
  </code></pre>
  
  <p>mongoreqs.html</p>
  
  <pre><code>&lt;!-- extend from base layout --&gt;
  
  {% extends "base.html" %}
  
  
  {% block content %}
  
      &lt;h2&gt;Open Requisitions MONGO DB &lt;/h2&gt;
      &lt;table&gt;
      &lt;th&gt;&lt;strong&gt;Question&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;URL &lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Job Description&lt;/strong&gt;&lt;/th&gt;
  
      {% for req in reqs %}
              &lt;tr&gt;
              &lt;td&gt;{{ req["Question"] }}&lt;/td&gt;
              &lt;td&gt;&lt;a href="{{ req['JobDetailLink'] }}" target="blank"&gt;Job Apply Link&lt;/a&gt;&lt;/td&gt;
              &lt;/th&gt;&lt;td&gt;{{ req['JobDescription']|safe }}&lt;/td&gt;
  
          &lt;/tr&gt;
      {% endfor %}
      &lt;/table&gt;
  {% endblock %}
  </code></pre>
  
  <p>Any thoughts or help would be greatly appreciated.</p>
  
  <p><a href="https://i.stack.imgur.com/PxeFJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PxeFJ.png" alt="Screen Shot of Output"></a></p>