问题的原因是框架自带的swagger工具文件(backend/dvadmin/utils/swagger.py)默认添加了视图的第一个默认的summary,也就是list:查询
代码:
swagger.py
def get_summary_and_description(self):
summary_and_description = super().get_summary_and_description()
summary = get_summary(self.__dict__.get('view').__doc__)
description = summary_and_description[1]
return summary, description
get_summary函数:
def get_summary(string):
if string is not None:
result = string.strip().replace(" ", "").split("\n")
return result[0]
self.__dict__.get('view').__doc__的打印为:
list:查询
create:新增
update:修改
retrieve:单例
destroy:删除
解决方法很简单,判断一些是否已经设置summary,如果没有才使用框架默认的,代码:
(backend/dvadmin/utils/swagger.py)
def get_summary_and_description(self):
summary_and_description = super().get_summary_and_description()
# 这是框架的代码,有点问题,这里注释掉
# summary = get_summary(self.__dict__.get('view').__doc__)
summary = summary_and_description[0]
print(self.__dict__.get('view').__doc__)
if not summary:
summary = get_summary(self.__dict__.get('view').__doc__)
description = summary_and_description[1]
return summary, description