DRF使用HyperlinkedModelSerializer的500錯誤

Django使用HyperlinkedModelSerializer錯誤

# django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "cure-detail".
# You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
#

解決方法

  • 第一步: 檢查對應View視圖的URL中是否 定義name值
  • 第二步: 檢查 name 值是否正確(name值不能自定義,規則’model-detail’)
  • 第三步: 可以排除錯誤–使用ModelSerializer
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章