首页  >  问答  >  正文

python - flask中markdowm提交文章图片显示不了

PHP中文网PHP中文网2741 天前206

全部回复(3)我来回复

  • PHP中文网

    PHP中文网2017-04-18 10:05:39

    allowed_tage 没有 img 图片给过滤掉了吧

    回复
    0
  • 黄舟

    黄舟2017-04-18 10:05:39

    你问题解决没有啊,我用了CKEditor提交之后图片也没了,另外问一下,你的编辑器怎么实现的?

    回复
    0
  • PHP中文网

    PHP中文网2017-04-18 10:05:39

    图片不显示是因为存在数据库中的img没有src属性。你需要告诉markdown你需要保留的属性

        @staticmethod
        def on_changed_body(target, value, oldvalue, initiator):
            allowed_tage = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
                            'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
                            'h1', 'h2', 'h3', 'p', 'img']
            attrs = {
                'img': ['src', 'alt']
            }
            target.body_html = bleach.linkify(bleach.clean(markdown(value, output_format='html'), tags=allowed_tage, attributes=attrs, strip=True))

    回复
    0
  • 取消回复