Blend images with Markdown in Flask app

I am creating a static site using Flask-FlatPages(and following Frozen-Flask).

In my pages I want to confuse text with images. This would be a naive way to do this:

## Look at *this* image:
<img src="{{ url_for('static', filename='images/image.png') }}">
Hmm, it does **not** seem to load.

{{ template tag }} not analyzed, because FlatPages launches the page through markdowns, and not through the Flask template system (if I'm not mistaken).

How do I get the correct image link?

Corresponding code

#app.py
from flask import Flask, render_template
from flask_flatpages import FlatPages

app = Flask(__name__)
pages = FlatPages(app)

@app.route('/tip/<path:path>')
def tip_detail(path):
    tip = pages.get_or_404(path)
    template = tip.meta.get('template', 'tip_detail.html')
    return render_template(template, tip=tip)

and

#tip_detail.html
<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<h1>{{ tip.meta.title }}</h1>
{{ tip }}
</body>
</html>
+3
source share
1 answer

Solved through the comment remaining https://github.com/naringas at https://github.com/SimonSapin/Flask-FlatPages/pull/1

, Flask-FlatPages Jinja. HTML. , Jinja .

#add these lines to app.py
def prerender_jinja(text):
    prerendered_body = render_template_string(Markup(text))
    return pygmented_markdown(prerendered_body)

app.config['FLATPAGES_HTML_RENDERER'] = prerender_jinja
+3

All Articles