Django REST Framework (DRF): TypeError: register () obtuvo un argumento de palabra clave inesperado 'base_name'

9

He actualizado a la djangorestframework==3.11.0versión anterior. Ahora tengo este error,

TypeError: register () recibió un argumento de palabra clave inesperado 'base_name'

Traceback
  ...
  ...
  ...
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/abu/projects/django-example/django2x/urls.py", line 21, in <module>
    path('sample/', include('sample.urls')),
  File "/home/abu/.virtualenvs/django-example/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  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 "/home/abu/projects/django-example/sample/urls.py", line 6, in <module>
    router.register(r'musician', MusicianViewset, base_name='musician')
TypeError: register() got an unexpected keyword argument 'base_name'
Arakkal Abu
fuente

Respuestas:

21

De las notas de lanzamiento de Django RestFramework y el DRF 3.9anuncio mencionaron que

Desaprobar el Router.register base_nameargumento a favor de basename. # 5990


Lo que significa que el argumento base_nameya no está disponible en DRF=3.11adelante y en su basenamelugar se usa

Entonces, cambie la configuración de su enrutador como,

router.register(r'musician', MusicianViewset, basename='musician')
router.register(r'album', AlbumViewset, basename='album')
Arakkal Abu
fuente