【发布时间】:2020-02-25 09:02:26
【问题描述】:
我有一个基于 Django-REST-framework 类的视图/端点,看起来像这样:
from rest_framework.generics import RetrieveUpdateAPIView
from .serializers import ViewSerializer
INPUT_FORMAT = {
"input1": [9, 23, 55],
"input2": "string",
"input3": "boolean",
}
class View(RetrieveUpdateAPIView):
"""
Docstring describing the endpoint.
Would like to integrate the content of INPUT_FORMAT here.
"""
serializer_class = ViewSerializer
def get_object(self):
# blahblah
pass
我想在文档字符串中集成常量INPUT_FORMAT,因为它在代码中的多个位置使用。我试过this 和this 但没有成功。有可能吗?
【问题讨论】:
-
我已经编辑了我的问题以包含一个解决方案 - 但请注意,你最好不要这样做,而只是硬编码你的文档字符串。我已经在答案中解释了原因。
标签: python django-rest-framework docstring