Reading a .json file using python - Flask
<p>I'm trying to read a <code>.json</code> file from within my Flask application using:</p>

<pre><code>def renderblog():
    with open(url_for("static", filename="blogs.json")) as blog_file:
        data = json.load(blog_file)
</code></pre>

<p>However I get the error:</p>

<pre><code>FileNotFoundError: [Errno 2] No such file or directory: '/static/blogs.json'
</code></pre>

<p>Now I know for a fact that the directory exists within my project structure, but I have no idea why I'm getting this error. Any ideas? Is there a specific way to retrieve <code>.json</code> in Flask? </p>

<p>You generated a <em>URL path</em>, not a path to the local static folder. Use the <a href="http://flask.pocoo.org/docs/0.11/api/#flask.Flask.static_folder" rel="nofollow"><code>app.static_folder</code> attribute</a> instead:</p>

<pre><code>def renderblog():
    filename = os.path.join(app.static_folder, 'blogs.json')
    with open(filename) as blog_file:
        data = json.load(blog_file)
</code></pre>

python json flask