Django 2 Web Development Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

The procedure to put the revision number in the STATIC_URL settings consists of the following two steps:

  1. Insert the following content:
# utils/misc.py
import subprocess


def get_media_svn_revision(absolute_path):
repo_dir = absolute_path
svn_revision = subprocess.Popen(
"svn info | grep 'Revision' | awk '{print $2}'",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=repo_dir,
universal_newlines=True)
rev = svn_revision.communicate()[0].partition('\n')[0]
return rev
  1. Modify the settings.py file and add the following lines:
# settings.py
# ... somewhere after BASE_DIR definition ...
from utils.misc import get_media_svn_revision
STATIC_URL = f'/static/{get_media_svn_revision(BASE_DIR)}/'