How to retrieve data from RethinkDB via Django view?

余生长醉 提交于 2020-01-17 05:37:48

问题


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 ?

来源:https://stackoverflow.com/questions/33113672/how-to-retrieve-data-from-rethinkdb-via-django-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!