0

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 ?

Satheesh Panduga
  • 779
  • 1
  • 8
  • 28
  • I assume that you're following http://c2journal.com/2013/03/25/django-and-rethinkdb-a-tutorial/ . Is it possible that you have to create the table first through the .save() method before you can use `get()` on it? You might also need to pass in a table ID when constructing the MyTable object. – Daniel Mewes Oct 14 '15 at 22:48
  • Did you find an answer to this question Sathish? – dalanmiller Oct 26 '15 at 17:57
  • Hi Dalanmiller, I used direct python script to insert row into RethinkDB in my project... and also, I could get the custom middleware work perfectly :) Thanks for your inputs so far! – Satheesh Panduga Oct 26 '15 at 19:11
  • Hi Miller, When can we expect the official support of Rethinkdb in Django? – Satheesh Panduga Oct 26 '15 at 19:26
  • @SathishPanduga I wouldn't expect the Django project to add RethinkDB support. See [this Django wiki page](https://code.djangoproject.com/wiki/NoSqlSupport) on NoSQL support generally: `"This is not part of the official Django development efforts."` – chucksmash Oct 29 '15 at 19:18

0 Answers0