Flask {{ STATIC_URL }} giving a 304 redirect when the static directory is unspecified

flask, python

Solution

HTTP response 304 is for "Redirection to a previously cached result".

This means Flask is telling your browser that it already has the content.

Clear your Browser cache and you will notice that Flask returns a 200 on your next request.

Problem

Let's say I have a Flask application where ``` app = Flask(__name__, static_url_path='') ``` That is, `{{ STATIC_URL }} == ""` (empty string) and the static files are not stored under a dedicated `/static` directory (e.g. `http://www.example.com/img/logo.png` instead of `http://www.example.com/static/img/logo.png`) Is it ok if I just leave it this way? The GET requests to any URL that contains `{{ STATIC_URL }}` give a `304` redirect instead of a `200` status code if I leave the variable in my code. Is it necessary to: - Delete all occurrences of `{{ STATIC_URL }}` in my templates? - Create a real static directory instead of just setting it equal to an empty string? - Leave all occurrences of `{{ STATIC_URL }}` in my templates so that I can set a new static directory in the future if necessary?

Original source