Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I add Django admin static files to my git repo?

I ran manage.py collectstatic on my webapp and now I have a new static folder with only Django admin files (so far I've been using just CDNs for my project CSS and JS files). Should I track these admin static files on my git repo? What's the best practise?

like image 947
Giacomo Sarrocco Avatar asked Jan 09 '17 22:01

Giacomo Sarrocco


People also ask

What is use of static files in Django?

django. contrib. staticfiles collects static files from each of your applications (and any other places you specify) into a single location that can easily be served in production. For an introduction to the static files app and some usage examples, see How to manage static files (e.g. images, JavaScript, CSS).

What is the difference between media and static files in Django?

Static files are meant for javascript/images etc, but media files are for user-uploaded content.

Can Django serve static files in production?

During development, as long as you have DEBUG set to TRUE and you're using the staticfiles app, you can serve up static files using Django's development server. You don't even need to run the collecstatic command.


1 Answers

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.

like image 198
2ps Avatar answered Oct 18 '22 16:10

2ps