AttributeError при загрузке файла pickle из views.py

Я получаю ошибку AttributeError: Can't get attribute 'predictionFunction' on <module 'main' from location of manage.py . Когда я не регистрирую viewfunction в url, predictionFunction загружается, но когда я регистрирую его в urls, он показывает ошибку. Для справки вот как выглядит мой файл views.py:

api_view(['GET'])
def predictLaptopPrice(request):
    parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    file_path = os.path.join(parent_dir, 'predictionFunction.pkl')
    print("File path:", file_path)
    with open(file_path, 'rb') as file:
        predictionFunction = pickle.load(file)
        file.close()
    print("Loaded prediction function:", predictionFunction)
    processor_speed = request.GET.get('processor_speed')
    ram_size = request.GET.get('ram_size')
    storage_capacity = request.GET.get('storage_capacity')
    result = predictionFunction([[processor_speed, ram_size, storage_capacity]])
    return Response({'price': result[0]}, status=status.HTTP_200_OK)

Я искал везде, что это за ошибка, но не знаю, что происходит.

Вернуться на верх