由于Django的思维方式对我来说依然非常陌生,所以我很抱歉。我试图生成一个非常简单的页面,只是列出了使用Neo4j和Django(1.9.7)的简单密码查询的所有结果,我使用Python Neo4j驱动程序从Django访问数据库。然而,我陷入了困境,并且已经达到了我只是盲目地尝试事物的地步,因此我希望得到关于我想要实现的基本内容的指示/建议。使用Django查询Neo4j数据库
models.py
from django.views.generic.listimport ListView
from neo4j.v1 import GraphDatabase, basic_auth
from django.db import models
# Connect to DB
driver=GraphDatabase.driver("foo1",auth=basic_auth("foo2","foo3"))
session=driver.session()
class Stuff(models.Model):
query = "MATCH (t:Time) return t"
results=session.run(query)
# Sanity check -> This just shows that the database and query both work
for foo in results:
print foo
break
def __str__(self):
return results
views.py
from django.views.generic.list import ListView
from .models import Stuff
# I assume that I should be using a ListView here (as I was trying to get a queryset or similar from my models).
class IndexView(ListView):
template_name = 'index.html'
def get_queryset(self):
fooList = []
for record in Stuff.objects.get():
fooList.append(record)
return fooList
index.html的(因为我还没有成功地得到这个 '秀' 还没有测试)
{% block body %}
{% if fooList %}
<h1>Woot!</h1>
{% endif %}
{% endblock %}
以上几位显然不起作用,并抱怨Stuff
没有任何objects
,但我totall如何继续下去(因为我一直无法在Django中使用这个驱动程序找到任何好的示例/文档)。
你是说你没有从Neo4j查询中得到结果吗?你能否更具体地处理你所面临的问题。 – EngineeredBrain