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

Python3 manage.py 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/manage.py 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!

Comments

Back to Home
John Solly Profile Picture
John Solly Profile Picture

John Solly

A hands-on AI practitioner who transitioned to a CTO role to broaden my impact.

Most of my career has been dedicated to developing spatial systems at Esri, startups, and federal agencies. Currently, I lead technology strategy for Leidos' Health IT division, supporting agencies such as SSA, VA, and HHS.

My primary focus is the convergence of spatial computing and AI, enabling machines to interpret the physical world and applying these capabilities to meaningful missions.

Please reach out if you are interested in spatial systems or advancing AI within the federal government.