March 2020
Intermediate to advanced
608 pages
17h 17m
English
This method works only if each of your environments contains the full Git repository of the project—in some cases, for example, when you use Heroku or Docker for deployments—you don't have access to a Git repository and the git log command in the remote servers. In order to have the STATIC_URL with a dynamic fragment, you have to read the timestamp from a text file—for example, myproject/settings/last-modified.txt—that should be updated with each commit.
In this case, your settings would contain the following lines:
# settings/_base.pywith open(os.path.join(BASE_DIR, 'myproject', 'settings', 'last-update.txt'), 'r') as f: timestamp = f.readline().strip()STATIC_URL = f'/static/{timestamp}/'
You can make your Git repository ...