我正在尝试使用 django 中的渲染函数将一堆行返回到我的网页,但出现以下错误。
Request Method: POST
Request URL: http://localhost:8000/neoapp/user_rec.html
Django Version: 1.8.6
Python Version: 2.7.10
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'neoapp')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "C:\dev\web\neo\lib\site-packages\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\dev\web\project\neoapp\views.py" in user_rec
19. m = graph.cypher.execute("""MATCH (b:User)-[r:HAS_RATED]->(m:Movie), (b)-[s:SIMILARITY]-(a:User {userID:"""+str(uid)
File "C:\dev\web\neo\lib\site-packages\py2neo\core.py" in cypher
667. metadata = self.resource.metadata
File "C:\dev\web\neo\lib\site-packages\py2neo\core.py" in metadata
213. self.get()
File "C:\dev\web\neo\lib\site-packages\py2neo\core.py" in get
258. response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
File "C:\dev\web\neo\lib\site-packages\py2neo\packages\httpstream\http.py" in get
966. return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
File "C:\dev\web\neo\lib\site-packages\py2neo\packages\httpstream\http.py" in __get_or_head
943. return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "C:\dev\web\neo\lib\site-packages\py2neo\packages\httpstream\http.py" in submit
433. http, rs = submit(self.method, uri, self.body, self.headers)
File "C:\dev\web\neo\lib\site-packages\py2neo\packages\httpstream\http.py" in submit
362. raise SocketError(code, description, host_port=uri.host_port)
Exception Type: SocketError at /neoapp/user_rec.html
Exception Value: Operation not permitted
视图文件是-
from django.shortcuts import render
from neomodel import StructuredNode, StructuredRel, RelationshipTo, RelationshipFrom, StringProperty, IntegerProperty, DateTimeProperty
from models import *
from forms import UserForm
from py2neo import *
def user_rec(request):
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
# return render(request,'got_it.html',{
# 'message':request.POST['userid']
# })
uid = request.POST.get("userid")
graph = Graph("https://neo4j:goel@localhost:7474/db/data/")
m = graph.cypher.execute("""MATCH (b:User)-[r:HAS_RATED]->(m:Movie), (b)-[s:SIMILARITY]-(a:User {userID:"""+str(uid)
+"""}) WHERE NOT((a)-[:RATED]->(m)) WITH m, s.similarity AS sim, r.rating AS rating ORDER BY m.name, rating DESC WITH m.name AS movie,
COLLECT(rating)[0..3] AS ratings WITH movie, REDUCE(s = 0, i IN ratings | s + i)*1.0 / LENGTH(ratings) AS reco ORDER BY reco DESC
RETURN movie AS Movie, reco AS Recommendation limit 10""")
return render(request,'reco.html',{
'm': m
})
else:
form = UserForm()
return render(request, 'user_rec.html', {'form': form})
为什么我得到这个py2neo异常?我如何才能在我的 views.py 文件中运行查询?