首页 > 解决方案 > 使用 Django 在函数中调用函数会导致 NameError

问题描述

为了保持我的项目干净,我的CalculationLogic类有模块。我在我的views.py文件中调用这个类,比如:

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

在我的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})

不幸的是,在我的浏览器中调用此视图后,我得到 NameError未定义其他函数。哪一部分可能是错的?

标签: pythonfunction-call

解决方案


推荐阅读