Django REST Framework (DRF): TypeError: register () mendapat argumen kata kunci tak terduga 'base_name'

9

Saya telah memperbarui ke djangorestframework==3.11.0dari versi yang lebih lama. Sekarang saya punya kesalahan ini,

TypeError: register () mendapat argumen kata kunci tak terduga '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
sumber

Jawaban:

21

Dari catatan rilis Django RestFramework dan DRF 3.9pengumuman mereka menyebutkan itu

Mengecewakan Router.register base_nameargumen yang mendukung basename. # 5990


Yang berarti, argumen base_nametidak lagi tersedia mulai DRF=3.11dan digunakan basenamesebagai gantinya

Jadi, Ubah konfigurasi router Anda sebagai,

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