Django REST Framework (DRF): TypeError: register() got an unexpected keyword argument 'base_name'
Question:
I have updated to djangorestframework==3.11.0
from older version. Now I’ve got this error,
TypeError: register() got an unexpected keyword argument ‘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'
Answers:
From the release notes of Django RestFramework and DRF 3.9
announcement they mentioned that
Deprecate the Router.register
base_name
argument in favor of basename
. #5990
Which means, the argument base_name
is no longer available from DRF=3.11
onwards and use basename
instead
So, Change your router config as,
router.register(r'musician', MusicianViewset, basename='musician')
router.register(r'album', AlbumViewset, basename='album')
I have updated to djangorestframework==3.11.0
from older version. Now I’ve got this error,
TypeError: register() got an unexpected keyword argument ‘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'
From the release notes of Django RestFramework and DRF 3.9
announcement they mentioned that
Deprecate the
Router.register
base_name
argument in favor ofbasename
. #5990
Which means, the argument base_name
is no longer available from DRF=3.11
onwards and use basename
instead
So, Change your router config as,
router.register(r'musician', MusicianViewset, basename='musician')
router.register(r'album', AlbumViewset, basename='album')