Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-30-2021 12:54 PM
Probably been learning too much Python today. Excuse the tired newbie question.
Trying to use py2neo with flask templates (which are just WTForms with some extensions, which is using Jinja).
If I do a
mylist = graph.run ("MATCH (n:Things) return n")
render_template ( "somelist.html", mylist = mylist)
Then in the template I have to do
{% for thing in mylist %}
I can use the ".data()" function and "n.name as name, n.attribute as attribute" in the Cypher to get rid of the Cypher variable "n". But that is ugly and inflexible if I introduce another attribute to "thing"s.
Is there a "tidy" or normal way to "lose the cypher variable n"? So that the template doesn't need to know the structure of the Cypher result?
My queries are actually more complex so "run" is necessary (afaict), and I expect to be returning nodes of different types on some occasions, so it may make sense to lose the cypher variable very late, such as immediately before the "render_template" call. But having decided I want to render a bunch of "thing"s, I want to decouple the template from the Cypher query variable, so I just need to know the attributes of the node type in the template.
08-03-2021 12:12 AM
Hi,
I'm certainly not a Cypher expert. But maybe this will hint you in the right direction graph - How can I return all properties for a node using Cypher? - Stack Overflow
09-15-2021 12:07 AM
I think my question is more a py2neo one than a Cypher one, but some of those approaches may work.
I've been off learning more Python, so worst case I can fix the iteration behaviour in the tools 😉
All the sessions of the conference are now available online