python - flask中markdowm提交文章图片显示不了
PHP中文网
PHP中文网 2017-04-18 10:03:39
0
3
202
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
洪涛

allowed_tage Images without img have been filtered out

黄舟

Have you solved the problem? After I used CKEditor to submit, the pictures were gone. Also, I would like to ask, how did you implement it in your editor?

洪涛

The picture is not displayed because the img stored in the database does not have the src attribute. You need to tell markdown which attributes you need to retain

    @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))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!