Categories
Development

Is there a simpler way of calling JSON in a Jinja2 template?

I managed to call in a JSON file into my router and access the content in the template. However, I’m wondering if there’s a simpler way of calling my data. Is there a way to just call for example, and not ? Any help would be greatly appreciated.

router_article_02.py

@app.route('/article-02/welcome')
    def article_02_welcome():
        with app.open_resource("templates/article-02/data.json", "r" ) as data_file:
            data = json.load(data_file)

    return render_template("article-02/welcome.html", data = data)

article-02.html

<h1></h1>
<div class="overline">Category: </div>

Leave a Reply

Your email address will not be published. Required fields are marked *