问题
I have created my blog using Flask-FlatPages and the posts are in Markdown, the challenge I'm having is inserting images in my blog post. The traditional way of inserting images in markdown is not working.
I also tried this without success:
 }})
回答1:
Here is a quick fix! let's say we have a images folder, and we want to use the images/flower.jpg
Step 1: Put the images folder in the static folder.
Step 2: In the text, link the image with ../static/images/flower.jpg.
for example:

or
<img src="../static/images/flower.jpg" alt="flower">
回答2:
Here is what worked for me. It turns out that FLATPAGES_HTML_RENDERER is needed to achieve this goal.
Here is the code:
def my_renderer(text):
prerendered_body = render_template_string(text)
return pygmented_markdown(prerendered_body)
app = Flask(__name__)
app.config['FLATPAGES_HTML_RENDERER'] = my_renderer
pages = FlatPages(app)
This is also discussed on this post: https://github.com/SimonSapin/Flask-FlatPages/pull/1
回答3:
There are nothing wrong during the markdown to html conversion process.
I think it because bleach.clean() function.
You can try to add to allowed_tags.
allowed_tags = ['img']
allowed_attrs = {'img':['src','alt']};
target.body_html = bleach.linkify(bleach.clean(markdown(value,output_format='html'),tags=allowed_tags,attributes=allowed_attrs,strip=True));
来源:https://stackoverflow.com/questions/30835901/inserting-images-using-flask-flastpages