【问题标题】:How to switch off Description column in Django Rest Framework Documentation?如何关闭 Django Rest Framework 文档中的描述列?
【发布时间】:2018-01-27 22:47:44
【问题描述】:
是否可以关闭 Django Rest Framework 文档中的 Description 列?正如您在下面的屏幕截图中看到的,有一列Description。 username 和 password 的意思很明显,所以我不需要添加更多信息,但是空单元格看起来不太好。我只想为这种方法关闭它,因为例如在其他方法中我想有描述。有什么想法我该怎么做?
【问题讨论】:
标签:
python
django
python-2.7
python-3.x
django-rest-framework
【解决方案1】:
目前没有简单的方法可以做到这一点,因为“描述”列是在模板级别设置的。看到这个template。
为了能够以更好的方式做到这一点,您需要自定义 rest_framework/docs/link.html,也许在这里有一个模板标签来检查自定义标志:
{% elif link.fields|with_location:'form' %}
<h4>Request Body</h4>
<p>The request body should be a <code>"{{ link.encoding }}"</code> encoded object, containing the following items.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'form' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% endif %}
但我认为仅删除该列就考虑太多了。