回到顶部

Contents

ImportError: cannot import name 'QUERY_TERMS'

错误日志(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:
    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
captcha