首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django-rest-swagger无法将Markdown文档字符串解析/转换为HTML代码

django-rest-swagger无法将Markdown文档字符串解析/转换为HTML代码
EN

Stack Overflow用户
提问于 2014-01-06 03:31:06
回答 2查看 1.4K关注 0票数 3

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

我使用的是:

代码语言:javascript
复制
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:

代码语言:javascript
复制
@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时,描述被正确地翻译/呈现。

我是不是遗漏了什么?

EN

回答 2

Stack Overflow用户

发布于 2014-11-04 05:46:41

从v0.2.0版本开始,markdown在django-rest-swagger中可用!

只需显式安装markdown包即可(不会自动安装):

代码语言:javascript
复制
pip install markdown
票数 2
EN

Stack Overflow用户

发布于 2014-01-14 00:01:11

我不认为你错过了什么。Markdown仅在DRF可浏览API视图中使用。Swagger不使用Markdown,相反,DRF使用它来呈现描述。

Swagger只是使用ajax将描述和注释作为字符串进行传递。然后它将它们都呈现为html,您可以通过在docs字符串中包含html标记来检查它。所以它根本没有使用Markdown渲染器。

DRF使用Markdown来显示描述,这就是为什么它在可浏览的API中工作,而不是在api-docs中工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20938105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档