While working on my first Django application I’ve just been questioning how people usually treat their static files.

staticfiles directory in .gitignore?

  • Should staticfiles (or static) directories of Django projects be ignored using .gitignore?

In this stackoverflow thread they recommend to ignore the static directory using a .gitignore file.
Instead they call collectstatic during the deployment process.

But aren’t these files actually needed for the application?
How can they work together with others (on a remote repository, using Github for example), if everyone always ignores the static directory?
I understand that they serve the static directory manually during the deployment process.
Therefor they use a cloud storage (like AWS S3) from where they feed the static files into the app while deploying.

But how do they behave, if someone wants to change something in the static directory?
How does working on the static directory work in practice, if you need to update and share them within the team regularly?

Anyway this is not my problem, yet.
As long as I work on a local repository on my own I can work and change my files in static as needed without getting under someones feet.
However I am thinking about this, because of the types of files which people store in the static directory:
Apperently it’s common to put stylesheets and images inside the static files directory.

stylesheets and images in Django projects

  • Where should stylesheets in Django projects be stored?

Does it make sense to store stylesheets in the static directory?
Intuitively I would put them into the templates directory – next to the HTML template files.
Doesn’t this make most sense, since we will use them there anyway?
Isn’t it unnecessarily complicated to store stylesheets in a static folder?
For images: okay – at least for those images which are uploaded by users.
But why would I store the images and the stylesheets, which are providing the basis for the appearance of the website, inside a static directory?

Apparently people put stylesheets in the static directory.
Even the official Django docs tutorial as well as the Django Girls tutorial teach us to store stylesheets inside a static directory.
Is this what people do in real life projects, too?

Let me summarize my findings:

  1. You typically use a directory with static files to be served by a cloud, right?
  2. You typically ignore your static directory using a .gitignore file, right?
  3. You typically store your images and stylesheets in the static directory, right?
  4. Images and stylesheets provide the basis for the websites‘ appearence and partially even for the functionality, right?

I think what confuses me is the following:

If teams work together, using a remote repository…

  1. How do they ensure that everyone always has the up to date version of the static files?
  2. Is it really the best practice to store images and stylesheets inside a static directory, instead of including them in some kind of frontend-related directory (for example templates)?

If you have an opinion of static directories, stylesheets, images and .gitignore files, please let leave a comment below😊