How to retrieve data from RethinkDB via Django vie

2019-09-01 10:45发布

问题:

Am trying to view data from RethinkDB in Django via custom middleware.

Below is the middleware code am using to connect to RethinkDB

@singleton
class rDBMiddleware(object):
    connection = None
def __init__(self):
  if self.connection == None:
      self.connection = r.connect(host=' 192.x.x.x ', port=28015, db=' re_test ').repl()

views.py -

from app.utils import rwrapper
from app.utils import fields

class MyTable(rwrapper):
  _db_table    = 'test_table'
  name = fields.CharField(max_length=60)
  skill = fields.CharField(max_length=60)
  edu = fields.CharField(max_length=60)

def page(request, template="app/reacthome.html",
    extra_context=None):
    item = MyTable().get()
   if extra_context is not None:
    context.update(extra_context)
return render_to_response(template, item,
    context_instance=RequestContext(request))

URLs.py

url(r'^reacthome', 'app.views.page', name='page'),

Template - reacthome.html

 <h1> TEST </h1>
      {% for it in item %}
      <h1>{{ it.name }}</h1>
      {% endfor %}

When I run this, I do not get the data.. and when debugged, I see that below line in my view doesn't get executed, and no error message :(

item = MyTable().get()

What could be missing here ?