How to do it...

The procedure to put the Git timestamp in the STATIC_URL setting consists of the following two steps:

  1. Add the following content to the misc.py file placed in utils/:
# utils/misc.py
import subprocess
from datetime import datetime

def get_git_changeset(absolute_path):
repo_dir = absolute_path
git_show = subprocess.Popen(
"git show --pretty=format:%ct --quiet HEAD",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=repo_dir,
universal_newlines=True)
timestamp = git_show.communicate()[0].partition(ā€˜ ā€™)[0]
try:
timestamp = datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return ""
changeset = timestamp.strftime(ā€˜%Y%m%d%H%M%Sā€™)
return changeset
  1. Import the newly created get_git_changeset() function in the settings and use it for the STATIC_URL path, as follows:
# settings.py
# ... somewhere after BASE_DIR definition ...
from utils.misc import get_git_changeset
STATIC_URL = f'/static/{get_git_changeset(BASE_DIR)}/'
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.186.164