我试图在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文件中运行查询?
答案 0 :(得分:2)
我可以使用https协议而不是http来重现这一点。
>>> from py2neo import Graph
>>> graph = Graph("https://localhost:7474/db/data/")
>>> m = graph.cypher.execute("match n return n limit 5")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/core.py", line 659, in cypher
metadata = self.resource.metadata
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/core.py", line 213, in metadata
self.get()
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/core.py", line 258, in get
response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 966, in get
return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 943, in __get_or_head
return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 433, in submit
http, rs = submit(self.method, uri, self.body, self.headers)
File "/Users/nicolewhite/Envs/science/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 362, in submit
raise SocketError(code, description, host_port=uri.host_port)
py2neo.packages.httpstream.http.SocketError: Operation not permitted
>>>
因此,您可以切换到http或查看https支持上的文档。 http://neo4j.com/docs/stable/security-server.html#security-server-https