Reputation: 3
I newly started to develop Django. I want to connect my python algorithm and Django web ui so I tried to connect both of them in views.py but I encountered a problem.
It says AttributeError at type object 'Services' has no attribute 'app' but I declared it in the queryOnMetadataModel.init. I don't know what is wrong. Could someone help me?
These are my code snippets;
from Neo4jConnection import App
import json
class Services:
def __init__(self):
uri = "neo4j+s://a50f760a.databases.neo4j.io:7687"
user = "neo4j"
password = "password"
self.app = App(uri, user, password)
def find_node_type(self,nodeName):
node_type = self.app.find_node_type(nodeName)
self.app.close()
return node_type
from django.shortcuts import render
from BitirmeTeziSourceCode.queryOnMetadataModel import Services
import sys
sys.path.append(".")
# Create your views here.
def home(request):
data = Services.find_node_type(Services , 'Region')
nodes = {
"nodes" : data
}
return render(request , "index.html" , nodes)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path("" , views.home)
]
I want to access output of Services.find_node_type(Services , 'Region') from index.html
Upvotes: 0
Views: 699
Reputation: 8837
You need to make instance first instead of directly using class so:
def home(request):
instance=Services()
data = instance.find_node_type('Region')
nodes = {
"nodes" : data
}
return render(request , "index.html" , nodes)
Note: Also it is better to write classes in singular case so it is better to write
Service
not.Services
Upvotes: 1