Flask——向博客文章中添加图片

未添加图片样式

添加图片设置:

1、允许渲染img标签

在数据库文章模型allowed_tags中添加img

2、clean函数加个参数attributes=attrs,

attrs = {
            '*': ['class'],
            'a': ['href', 'rel'],
            'img': ['src', 'alt'],
        }
target.body_html = bleach.linkify(bleach.clean(markdown(value,output_format='html'),tags=allowed_tags,attributes=attrs,strip=True))

3、在编写文章时使用markdown语法即可加入图片

![加载失败时的提示文本](url)

插入图片成功。需要注意的是,图片url必须是外部链接url,直接拖拉到和粘贴图片还没实现。

原文地址:https://www.cnblogs.com/ldy-miss/p/8854227.html