py2neo+flask+cytoscape.js展示Neo4j图数据

1. Python虚拟环境中安装py2neo模块:(sandbox) C:\Users\bing.yao\sandbox\Scripts>pip install py2neo

2. Python虚拟环境中安装flask模块:(sandbox) C:\Users\bing.yao\sandbox\Scripts>pip install flask

3. 安装Python IDE工具:PyCharm Community Edition

4. 编写helloworld Python代码

5.1. 进入Python虚拟环境:C:\Users\bing.yao\sandbox\Scripts>activate.bat

5.2. 执行Python代码启动应用:(sandbox) C:\Users\bing.yao\sandbox\py\flaskweb>python helloworld.py

6. 浏览器访问应用:http://127.0.0.1:5000/(到此表示Flask安装成功)

7. 搭建网站目录结构,包括:static/css、static/js、templates

8. 访问https://js.cytoscape.org/,下载最新版 cytoscape.min.js (3.18.0)

9. 访问https://jquery.com/download/,下载最新的jQuery (jquery-3.6.0.min.js)

下一步的前提:

已安装Neo4j,且根据官网示例创建了节点/关系

启动Neo4j:C:\Users\bing.yao>neo4j console

10. 在Python虚拟环境,进入Python Sheel,测试能否用py2neo来获取neo4j的节点及关系

(sandbox) C:\Users\bing.yao\sandbox\Scripts>python

>>> from py2neo import Graph

>>> graph = Graph()

>>> graph.run('match (n:Person) return n.name, n.born limit 5').to_table()

顺利获得5条记录,如下图:

如果:进入Python Sheel,执行下面代码报错:

>>> from py2neo import Graph

>>> graph == Graph()

……

py2neo.database.work.ClientError: [Security.Unauthorized] The client is unauthor

ized due to authentication failure.

处理方式:

找到neo4j.conf文件,打开,删除dbms.security.auth_enabled=false前面的#字符

重新启动Neo4j服务即可

(到此表示测试py2neo获取Neo4j数据成功)

11. 编写app.py

12. 编写getJsonData.js

13. 编写index.html

14. 编写style.css

(11~14的代码贴在下一篇文章)

15. 在Python虚拟环境运行app.py,访问 http://10.110.41.71:5000/,成功将Neo4j数据在Web页面展示,如下图:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容