After modifying static files (ckeditor, fonts, etc), I needed to run:

Python3 collectstatic

in both environments to sync QA and prod environments. A web search for 'commit static files to source control' reveals this StackOverflow Question. The top answerer had an interesting approach:

While you can absolutely check these files in, I typically recommend not checking in the collected static files into git (we use .gitignore to ignore them). Instead, we call collectstatic during our build/deploy steps so that if anyone ever adds new static files, they are collected and copied to the proper output directory for serving by nginx or sent up to s3. If you want to check them into git, I would recommend having collectstatic as a precommit hook so that no one accidentally forgets to run it when adding a new static file.

I've never used precommit hooks, but the git hooks doc is super straight-forward. If you're using VSCODE, you'll first need to remove the file exclusion of .git so that the IDE can see the .git folder in the catalog view.

Settings -> Files:exclude

Then, you copy the pre-commit.sample file inside .git/hooks and rename it to pre-commit. Inside pre-commit, I add one line:

~/blogthedata/venv/bin/python3 ~/blogthedata/django_project/ collectstatic --noinput

Now, whenever youdo  a git commit, the collectstatic command runs to ensure static files collect.

A final step is to remove 'static/' from .gitignore so git recognizes and uploads all the static files.

Now I you don't have to run collectstatic on prod!

Back to Home
 Profile Picture
Profile Picture

About John Solly

I am a Senior Software Engineer with a focus on geospatial applications, based in the Columbus, OH metropolitan area. This blog is where I delve into the intricacies of GIS (Geographic Information Systems), offering deep dives into different components of the geospatial technology stack. For those who share a passion for GIS and its applications, you've found a spot to explore and learn.

Interested in collaborating or learning more about my work? Take a look at my portfolio for a showcase of my projects and expertise.


  • No comments yet.
Login to Comment