到目前为止,我知道django-rest-swagger从v0.1.10开始支持Markdown语法中的文档字符串。但是当我尝试查看文档时,它显示为纯文本,而不是解析和转换为HTML代码。

我使用的是:
Django==1.5
Markdown==2.3.1
djangorestframework==2.3.10
django-rest-swagger==0.1.11
SWAGGER_SETTINGS = {
"exclude_namespaces": [], # List URL namespaces to ignore
"api_version": '0.1', # Specify your API's version
"api_path": "", # Specify the path to your API not a root level
"enabled_methods": [ # Specify which methods to enable in Swagger UI
'get',
'post',
'put',
'patch',
'delete'
],
"api_key": '', # An API key
"is_authenticated": True, # Set to True to enforce user authentication,
"is_superuser": False, # Set to True to enforce admin only access
}API示例代码function-based-view:
@api_view(['POST'])
def dummy(request):
'''
Lorem ipsum `dolor` sit amet, consectetur adipiscing elit. Etiam sodales lacus at _nulla_ fringilla fringilla.
### Consectetur adipiscing:
* __dummy_var__: Nunc ut erat justo. Duis turpis augue, posuere a ornare sed,
* another: Vestibulum suscipit congue neque sed faucibus.
* `code`: Cras sit amet ullamcorper ipsum.
'''
pass当直接浏览API时,描述被正确地翻译/呈现。

我是不是遗漏了什么?
发布于 2014-11-04 05:46:41
从v0.2.0版本开始,markdown在django-rest-swagger中可用!
只需显式安装markdown包即可(不会自动安装):
pip install markdown发布于 2014-01-14 00:01:11
我不认为你错过了什么。Markdown仅在DRF可浏览API视图中使用。Swagger不使用Markdown,相反,DRF使用它来呈现描述。
Swagger只是使用ajax将描述和注释作为字符串进行传递。然后它将它们都呈现为html,您可以通过在docs字符串中包含html标记来检查它。所以它根本没有使用Markdown渲染器。
DRF使用Markdown来显示描述,这就是为什么它在可浏览的API中工作,而不是在api-docs中工作。
https://stackoverflow.com/questions/20938105
复制相似问题