0

to keep my project clean I have module with my CalculationLogic class. I call this class in my views.py file, like:

def method_in_views_file(request):
    cl = CalculationLogic()
    return cl.method_in_calculation_logic()

In my CalculationLogic:

def other_function(self,x):
    # some logic here #
    return result

def method_in_calculation_logic(self,args):
    # some logic here #
    x = ['x','y','z']
    data = other_function(x)
    return render(request,'file.html',{'data':data})

Unfortunately after calling this view in my browser I get NameError that other function is not defined. Which part can be wrong here?

Frendom
  • 508
  • 6
  • 24
  • 1
    You should call this with `self.other_function(x)`, (so `self.`) – Willem Van Onsem Feb 14 '20 at 20:33
  • 1
    The question has nothing to do with django; it's simply a matter of how classes work. `other_function` as written means a *global* `other_function`; to call another method on the "current" instance requires explicitly calling it on `self.`, for the same reason that the explicit `cl.` is needed in the external code. – Karl Knechtel Feb 14 '20 at 20:34

0 Answers0