django-rest-framework学习之Relationships & Hyperlinked APIs--2017年4月17日至18日
Relationships & Hyperlinked APIs 参考链接: http://www.weiguda.com/blog/23/ http://www.django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis/ 目前我们API中的关系用primary keys展示,这部分我们会通过hyperlinking提高我们API的内聚性和扩展性 【1】给API的根节点传建一个端点 在views.py中添加: from rest_framework.decorators import api_view from rest_framework.response import Response #reverse函数返回完全合格的URLs from rest_framework.reverse import reverse @api_view(['GET']) def api_root(request,format=None): return Response({ 'users':reverse('user-list',request=request,format=format), 'myLesson':reverse('myLesson-list',request=request,format