Flask background-image not showing
<p>My background-image works only for this template that has @app.route('/').</p>

<pre><code> &lt;header class="intro-header" style="background-image: url('static/img/home.jpg')"&gt;
</code></pre>

<p>This works perfectly fine when:</p>

<pre><code>@app.route('/')
def home():
    return render_template('post.html')
</code></pre>

<p>Everything works. I get this:</p>

<pre><code>127.0.0.1 - - [19/Sep/2016 21:07:11] "GET /static/img/home.jpg HTTP/1.1" 304 
</code></pre>

<p>But when I use same template with:</p>

<pre><code>@app.route('/post/')
def post():
     return render_template('post.html')
</code></pre>

<p>I get this:</p>

<pre><code>127.0.0.1 - - [19/Sep/2016 21:15:23] "GET /post/static/img/home.jpg HTTP/1.1" 404 -                                                                          
</code></pre>

<p>And background-image is blank.</p>

<p><a href="http://flask.pocoo.org/docs/0.11/quickstart/#static-files" rel="nofollow">This is a simple problem can solved by Flask documentation</a></p>

<p>Anyway, you should use something like this in your template:</p>

<pre><code>background-image: url({{ url_for('static', filename='img/home.jpg') }})
</code></pre>

<p>but if you don't want to use Flask methods use :</p>

<pre><code>url('/static/img/home.jpg')
</code></pre>

<p>or use another web server instead of flask default web server for your files like Apache and access via <code>http://yoursite/static/img/home.jpg</code></p>

python html css flask