无法从“ rest_framework.decorators”导入名称“ detail_route”

时间:2019-08-02 02:35:51

标签: python django python-3.x django-rest-framework wagtail

我正在尝试运行长爪,但是当我python manage.py migrate时出现错误。

$python manage.py makemigrations catalog home                                                                                         
Traceback (most recent call last):                                                                                                    
  File "manage.py", line 11, in <module>                                                                                              
    execute_from_command_line(sys.argv)                                                                                               
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line                                                                                                                                  
    utility.execute()                                                                                                                 
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute              
    self.fetch_command(subcommand).run_from_argv(self.argv)                                                                           
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv            
    self.execute(*args, **cmd_options)                                                                                                
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/base.py", line 361, in execute                  
    self.check()                                                                                                                      
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check                    
    include_deployment_checks=include_deployment_checks,                                                                              
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks              
    return checks.run_checks(**kwargs)                                                                                                
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks                
    new_errors = check(app_configs=app_configs)
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/urls/resolvers.py", line 398, in check
    for pattern in self.url_patterns:
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/urls/resolvers.py", line 579, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/django/urls/resolvers.py", line 572, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/x/Documents/Longclaw/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/x/Documents/bakery/bakery/urls.py", line 10, in <module>
    from longclaw import urls as longclaw_urls
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/longclaw/urls.py", line 2, in <module>
    from longclaw.basket import urls as basket_urls
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/longclaw/basket/urls.py", line 2, in <module>
    from longclaw.basket import api
  File "/home/x/Documents/Longclaw/lib/python3.7/site-packages/longclaw/basket/api.py", line 1, in <module>
    from rest_framework.decorators import detail_route, list_route
ImportError: cannot import name 'detail_route' from 'rest_framework.decorators' (/home/x/Documents/Longclaw/lib/python3.7/site-packages/rest_framework/decorators.py)

使用Python 3.7.2

  • $ pip冻结
    • beautifulsoup4 == 4.6.0
    • certifi == 2019.6.16
    • chardet == 3.0.4
    • Django == 2.2.4
    • django-countries == 5.3.3
    • django-extensions == 2.2.1
    • django-ipware == 2.1.0
    • django-modelcluster == 4.4
    • django-taggit == 0.24.0
    • django-treebeard == 4.3
    • djangorestframework == 3.10.2
    • draftjs-exporter == 2.1.6
    • html5lib == 1.0.1
    • idna == 2.8
    • longclaw == 1.0.2
    • 枕头== 6.1.0
    • pytz == 2019.2
    • requests == 2.22.0
    • six == 1.12.0
    • sqlparse == 0.3.0
    • Unidecode == 1.1.1
    • urllib3 == 1.25.3
    • wagtail == 2.6
    • webencodings == 0.5.1
    • Willow == 1.1

1 个答案:

答案 0 :(得分:6)

这是因为detail_route已从DRF 3.8中弃用。您也可以检查他们的change-log。另外,您可以使用actions装饰器。例如:

from rest_framework.decorators import action

@action(detail=True, methods=['post'])
def set_password(self, request, pk=None):
   ....