解决使用drf-haystack报错ImportError: cannot import name get_count

如果在配置完haystack并启动程序后,出现如下异常,是因为drf-haystack还没有适配最新版本的REST framework框架
解决使用drf-haystack报错ImportError: cannot import name get_count_第1张图片

可以通过修改REST framework框架代码,补充_get_count函数定义即可
文件路径 虚拟环境下的
lib/python3.6/site-packages/rest_framework/pagination.py

def _get_count(queryset):
    """
    Determine an object count, supporting either querysets or regular lists.
    """
    try:
        return queryset.count()
    except (AttributeError, TypeError):
        return len(queryset)

你可能感兴趣的:(DJango)