您好,登錄后才能下訂單哦!
最近在寫一個(gè)CMDB的項(xiàng)目,遇到drf與django版本問題...
AttributeError at /
module 'markdown' has no attribute 'version'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.1.1
Exception Type: AttributeError
Exception Value:
module 'markdown' has no attribute 'version'
Exception Location: D:\Code\Python\AutoCMDBViewer\venv\lib\site-packages\rest_framework\compat.py in <module>, line 161
Python Executable: D:\Code\Python\AutoCMDBViewer\venv\Scripts\python.exe
Python Version: 3.6.5
Python Path:
['D:\\Code\\Python\\AutoCMDBViewer',
'D:\\Code\\Python\\AutoCMDBViewer',
'D:\\Code\\Python\\AutoCMDBViewer\\venv\\Scripts\\python36.zip',
'C:\\ProgramData\\Anaconda3\\DLLs',
'C:\\ProgramData\\Anaconda3\\lib',
'C:\\ProgramData\\Anaconda3',
'D:\\Code\\Python\\AutoCMDBViewer\\venv',
'D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages',
'D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages\\setuptools-39.1.0-py3.6.egg',
'D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages\\pip-10.0.1-py3.6.egg',
'C:\\Apps\\PyCharm\\helpers\\pycharm_matplotlib_backend']
(venv) D:\Code\Python\AutoCMDBViewer>pip freeze
asn1crypto==0.24.0
cffi==1.11.5
cryptography==2.3.1
Django==2.1.1
django-filter==2.0.0
djangorestframework==3.8.2
idna==2.7
Markdown==3.0
pycparser==2.18
PyMySQL==0.9.2
pytz==2018.5
six==1.11.0
打開drf源碼目錄下的 compat.py
文件,我的路徑是: D:\Code\Python\AutoCMDBViewer\venv\Lib\site-packages\rest_framework\compat.py
定位到157行代碼進(jìn)行修改:
try:
import markdown
if markdown.__version__ <= '2.2': # 將version修改為__version__即可
HEADERID_EXT_PATH = 'headerid'
LEVEL_PARAM = 'level'
elif markdown.__version__ < '2.6': # 將version修改為__version__即可
HEADERID_EXT_PATH = 'markdown.extensions.headerid'
LEVEL_PARAM = 'level'
else:
HEADERID_EXT_PATH = 'markdown.extensions.toc'
LEVEL_PARAM = 'baselevel'
def apply_markdown(text):
"""
Simple wrapper around :func:`markdown.markdown` to set the base level
of '#' style headers to <h3>.
"""
extensions = [HEADERID_EXT_PATH]
extension_configs = {
HEADERID_EXT_PATH: {
LEVEL_PARAM: '2'
}
}
md = markdown.Markdown(
extensions=extensions, extension_configs=extension_configs
)
md_filter_add_syntax_highlight(md)
return md.convert(text)
except ImportError:
apply_markdown = None
markdown = None
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。