问题描述:
···
在Django的django-rest-framework框架学习过程中,遇到一个问题,就是在使用HyperlinkedModelSerializer这种类型的序列化器进行序列化时,会出现一种现象,表现为:
1:服务器状态会显示错误:Could not resolve URL for hyperlinked relationship using view name “XXX-detail”. You may have failed to include the related model in your API, or incorrectly configured the lookup_field attribute on this field.
2:数据库的字段已经写成功。
3:浏览器页面会报错,提示内容与服务器状态的错误信息相同,意思是在创建URL相关的链接详情信息时没有成功。
···
问题解决:
1 | 1:在app的urls中区分批量显示,与单个显示的路由,并在views文件中创建对应方法: |