Closed thmohd closed 8 years ago
Are you using virtualenv?
Yes I do.
Hey, did you figure it out? I figured it was something to do with not activating the virtualenv.
Yes, actually it was. My bad I didn't write here. But I am new to Neo4j and Python :), and keep changing stuff. I also realized that Neo4j V3 released so I got rid of py2neo and start using Python Driver.
Thank you so much and I am sorry again.
No worries! Good luck.
I apologize if my question is not related. But, I thought you might be able to help.
So, I am using Flask and Neo4j v3. and there is a caching happening on the data. I tried all methods to prevent caching in Flask and the browser, but I still get the same issue. Even if I open the page in different browsers , the data doesn't change.
I checked Neo4j conf. and there was no caching enabled. The only way to see the results is when turn the python server off then rerun the command again.
Thanks
Are you using py2neo or neo4j-driver?
I am using Neo4j-Driver
Are you using any caching libraries with Flask?
Nope and I even added after_request function to prevent caching in HTML headers but no luck with that too.
Can you post the relevant code to reproduce the issues?
The issue is there is no error or warning. It's just the pages are cached somehow and let's say for the following example, I added City and want to see the new added city in the School form so I can Add the assign the school to it, that's where the issue appear and wont show the new city even I open different browsers. Sorry if the code is messed up it need a lot of refactoring and testing.
ps. exist() is just a helper function to check if node exist.
:: ROUTES
@admin.route('/city/add/', methods=["GET", "POST"])
def add_city():
form = AddCityForm()
if form.validate_on_submit():
name = form.name.data
country = form.country.data
city = City()
if not city.AddCity(name, country):
flash("It's exisit", "danger")
else:
flash("Has been added", "success")
return render_template("rendering_form.html", form=form, title="Add City")
@admin.route('/university/add/', methods=['GET','POST'])
def add_university():
form = AddUniversityForm()
if form.validate_on_submit():
name = form.name.data
website = form.website.data
description = form.description.data
phone = form.phone.data
address = form.address.data
city = form.city.data
univ = University()
if not univ.addUniv(name, description, address, phone, website, city):
flash('It is Exists','danger')
else:
flash('Has been added!','success')
return render_template("rendering_form.html", form=form, title="Add University")
::::FORMS
class AddCityForm(Form):
name = StringField("City Name - Description", validators=[Required()])
country = SelectField('Country',choices=find_all_countries())
submit = SubmitField("Submit")
class AddUniversityForm(Form):
name = StringField("University Name", validators=[Required()])
description = TextAreaField("Description")
website = StringField("Website", validators=[Required()])
phone = StringField("Phone")
city = SelectField('City',choices=find_all_cities())
address = StringField("Address")
submit = SubmitField("Submit")
:::MODELS
class City:
def __init__(self):
self.nid = str(uuid.uuid4())
self.tag = self.__class__.__name__
def AddCity(self, name, country):
if not exist(tag=self.tag, key="nid", value=self.nid):
session = driver.session()
query="MATCH (co:Country {nid:{country}}) " \
"CREATE (:City {nid:{nid}, name:{name}})" \
"-[:LOCATED_IN]->(co)"
session.run(query, {"country":country, "nid":self.nid, "name":name})
session.close()
return True
return False
class University:
def __init__(self):
self.nid = str(uuid.uuid4())
self.tag = self.__class__.__name__
def addUniv(self, name, description, address, phone, website, city):
if not exist(tag=self.tag, key="nid", value=self.nid):
session = driver.session()
query="MATCH (c:City {nid:{city}}) " \
"CREATE (:University {nid:{nid}, name:{name}, description:{description}" \
", address:{address}, phone:{phone}, website:{website}})-[:LOCATED_IN]->(c)"
session.run(query, {"nid":self.nid, "name":name, "description":description,
"address":address, "phone":phone, "website":website, "city":city})
session.close()
return True
return False
Hey Nicole,
I am trying to follow this code and I keep getting "ImportError: No module named py2neo", However, it works fine on python console in Pycharm.
Do you have any idea why this happen? I am using python3.5
Thanks