March 2020
Intermediate to advanced
608 pages
17h 17m
English
The procedure to put the Git timestamp in the STATIC_URL setting consists of the following two steps:
# versioning.pyimport subprocessfrom datetime import datetimedef get_git_changeset_timestamp(absolute_path): repo_dir = absolute_path git_log = subprocess.Popen( "git log --pretty=format:%ct --quiet -1 HEAD", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=repo_dir, universal_newlines=True, ) timestamp = git_log.communicate()[0] try: timestamp = datetime.utcfromtimestamp(int(timestamp)) except ValueError: # Fallback to current timestamp return datetime.now().strftime(