Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT
Stack How?
Stackorigin – The Community of Question and Answers Latest Articles
Read More About Python List Comprehension with examples
Python List Comprehension: Python List comprehension provides a much more short syntax for creating a new list based on the values of an existing list. Advantages of List Comprehension in Python: Time Efficient than loop Space Efficient than loop Needs ...
Do not accept an offer letter from companies.
Do not accept an offer letter from companies without verifying the following points. Designation Salary Details & CTC Distribution Leave Policies Working Hours & Days Medical Coverage/Insurance Probation Period Notice Period Benefits and Perks Bonus F&F Policy
How to call API using Ajax
AJAX stands for Asynchronous JavaScript and XML and its used for to make calls to the server to fetch some data. In this article, we will learn how to implement a simple API call using AJAX technology. How to use GET ...
Development:
STATIC_ROOT
is useless during development, it’s only required for deployment. While in development,STATIC_ROOT
does nothing. You even don’t need to set it. Django looks for static files inside each app’s directory (myProject/appName/static
) and serves them automatically. This is the magic done bymanage.py runserver
whenDEBUG=True
. DeploymentDevelopment
STATIC_ROOT
is useless during development, it’s only required for deployment. While in development,STATIC_ROOT
does nothing. You even don’t need to set it. Django looks for static files inside each app’s directory (myProject/appName/static
) and serves them automatically. This is the magic done bymanage.py runserver
whenDEBUG=True
.Deployment
When your project goes live, things differ. Most likely you will serve dynamic content using Django and static files will be served by Nginx. Why? Because Nginx is incredibly efficient and will reduce the workload off Django. This is where
STATIC_ROOT
becomes handy, as Nginx doesn’t know anything about your django project and doesn’t know where to find static files. So you setSTATIC_ROOT = '/some/folder/'
and tell Nginx to look for static files in/some/folder/
. Then you runmanage.py collectstatic
and Django will copy static files from all the apps you have to/some/folder/
. Extra directories for static files:STATICFILES_DIRS
is used to include additional directories forcollectstatic
to look for. For example, by default, Django doesn’t recognize/myProject/static/
. So you can include it yourself.STATICFILES_DIRS
is the list of folders where Django will search for additional static files aside from thestatic
folder of each app installed.