Bill Mei
Bill Mei

Reputation: 787

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

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:

  1. Delete all occurrences of {{ STATIC_URL }} in my templates?
  2. Create a real static directory instead of just setting it equal to an empty string?
  3. Leave all occurrences of {{ STATIC_URL }} in my templates so that I can set a new static directory in the future if necessary?

Upvotes: 8

Views: 15544

Answers (1)

Stephen Gornick
Stephen Gornick

Reputation: 392

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.

Upvotes: 16

Related Questions