首頁  >  問答  >  主體

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

PHP中文网PHP中文网2741 天前201

全部回覆(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
  • 取消回覆