发表文章出现问题,不知道是不是版本问题

来源:7-6 实现Markdown编辑与实时预览

慕婉清0635027

2020-05-09

TypeError at /articles/write-new-article/
render() got an unexpected keyword argument ‘renderer’
Request Method: GET
Request URL: http://127.0.0.1:8000/articles/write-new-article/
Django Version: 2.2
Exception Type: TypeError
Exception Value:
render() got an unexpected keyword argument ‘renderer’
Exception Location: /Users/php8er/.local/share/virtualenvs/zanhu-tgEnzapH/lib/python3.7/site-packages/django/forms/boundfield.py in as_widget, line 93
Python Executable: /Users/php8er/.local/share/virtualenvs/zanhu-tgEnzapH/bin/python
Python Version: 3.7.7
Python Path:
[’/Users/php8er/Desktop/zanhu’,
’/Users/php8er/Desktop/zanhu’,
’/Users/php8er/Desktop/zanhu’,
’/Users/php8er/Desktop/zanhu/zanhu’,
’/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display’,
’/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python37.zip’,
’/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7’,
’/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload’,
’/Users/php8er/.local/share/virtualenvs/zanhu-tgEnzapH/lib/python3.7/site-packages’,
’/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend’,
’/Users/php8er/Desktop/zanhu/zanhu’,
’/Users/php8er/Desktop/zanhu/zanhu’]
Server time: 星期六, 9 五月 2020 14:39:23 +0800

写回答

2回答

Jack

2020-05-09

厉害,这个回答要加精!

0
0

慕婉清0635027

提问者

2020-05-09

解决了,弄了好久,版本问题导致的,找到mardownx文件下的widgets.py文件下的render函数中,改两个地方

1,添加参数 renderer=None,

2.去掉c中的context

原因:Template.render()的参数必须是字典,弃用了Context


class MarkdownxWidget(forms.Textarea):

   def render(self, name, value, attrs=None, renderer=None):
       if 'class' in attrs.keys():
           attrs['class'] += ' markdownx-editor'
       else:
           attrs.update({'class':'markdownx-editor'})

       attrs['data-markdownx-editor-resizable'] = MARKDOWNX_EDITOR_RESIZABLE

       widget = super(MarkdownxWidget, self).render(name, value, attrs)

       t = get_template('markdownx/widget.html')
       c = ({
           'markdownx_editor': widget,
       })


       return t.render(c)

改了之后就能正常显示了


0
0

Django高级实战 开发企业级问答网站

融合Django高级用法/算法/设计模式/TestCase测试/云计算打造项目

900 学习 · 756 问题

查看课程