回到顶部

阅读目录

ImportError: cannot import name 'QUERY_TERMS'

错误背景(background )

Django 1.11 upgrade to Django 2.x

错误日志(error log)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\py_virtualenv\joyoo\lib\site-packages\django_filters\__init__.py", line 4, in <module>
    from .filterset import FilterSet
  File "E:\py_virtualenv\joyoo\lib\site-packages\django_filters\filterset.py", line 16, in <module>
    from .filters import (Filter, CharFilter, BooleanFilter, BaseInFilter, BaseRangeFilter,
  File "E:\py_virtualenv\joyoo\lib\site-packages\django_filters\filters.py", line 11, in <module>
    from django.db.models.sql.constants import QUERY_TERMS
ImportError: cannot import name 'QUERY_TERMS'

解决办法(solution)

source code location:..\Lib\site-packages\django_filters\filters.py

try:
    # djagno 1.11
    from django.db.models.sql.constants import QUERY_TERMS
except ImportError:
    # Django 2.1
    QUERY_TERMS = {
        'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
        'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
        'month', 'day', 'week_day', 'hour', 'minute', 'second', 'isnull', 'search',
        'regex', 'iregex',
    }

 

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: django.template.exceptions.TemplateDoesNotExist: django_filters/rest_framework/crispy_form.html
下一篇: List of Chromium Command Line Switches