2014-01-05 13 views
3

到目前爲止,我知道django-rest-swagger支持v0.1.10中Markdown語法的docstring。但是,當我嘗試查看文檔時,它顯示爲純文本而不是解析並將其轉換爲HTML代碼。django-rest-swagger未將Markdown文檔字符解析/翻譯爲HTML代碼

enter image description here

我使用:

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的示例代碼基於函數的視圖:

@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直接瀏覽,該描述被轉換/呈現正常。

enter image description here

我這麼想嗎?

+0

可否請您標籤Django的REST的架構添加到您的問題嗎?謝謝。 – cezar

+0

對!謝謝@cezar – trinchet

回答

1

我不認爲你錯過了任何東西。 Markdown僅用於DRF Browsable API視圖。 Swagger不使用Markdown,而是DRF使用它來呈現描述。

Swagger只是將描述和註釋作爲字符串傳遞,使用ajax。然後它將它們都呈現爲html,您可以通過在文檔字符串中包含html標記來檢查它。所以它根本不使用Markdown渲染器。

DRF使用Markdown顯示描述,這就是它在Browsable API中工作的原因,但不在API文檔中。

2

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

只是明確地安裝降價包(它不會自動安裝)這是需要:

pip install markdown