Hello Django developer,
I created a function on views, The path is api\views\collection.py:
@api_view(["GET"])
def getCollection(request, customer_id):
get_customer = CustomerInfo.objects.get(id=customer_id)
cx_Oracle.init_oracle_client(lib_dir='C:\instantclient_21_3')
dsn_tns = cx_Oracle.makedsn('', 1521, service_name='')
conn = cx_Oracle.connect(user='', password='', dsn=dsn_tns)
#c = conn.cursor()
#c.execute('select * from KULS_PROD.COLLECTION_VIEW_ALL_STATUS where APPNO =78') # use triple quotes if you want to spread your query across multiple lines
with conn.cursor() as cursor:
sql_collection = "SELECT LOANID as load_id , CIFID , IDNUMBER as cust_id" + \
"FROM KULS_PROD.COLLECTION_VIEW_ALL_STATUS WHERE IDNUMBER= " + str(get_customer.id_no) + " OR MOBILE1 = " + \
str(get_customer.mobile_no) + " OR PHONE1 = " + str(get_customer.mobile_no) + " OR PHONE2 = " + str(get_customer.mobile_no)
c = cursor.execute(sql_collection)
for row in c:
print("hello world")
print (row[0], '-', row[1])
columns = [col[0] for col in cursor.description]
row_collection = [
dict(zip(columns, row))
for row in cursor.fetchall()
]
res = {
'data': row_collection,
}
return Response(res)
And then I want to call this function in api\urls.py:
from django.urls import path
from . import views
path("get_collection/<int:customer_id>/",
views.getCollection,
name='collection'
),
I got this error message below:
views.getCollection,
AttributeError: module 'api.views' has no attribute 'getCollection'
Could you please help me ? I really appreciate it