75๐
According to the docs, collectstatic will copy the files from various folders into STATIC_ROOT.
Therefore, you cannot use the STATIC_ROOT
folder in STATICFILES_DIRS
.
Solution: change STATIC_ROOT
to e.g. STATIC_ROOT = '/home/username/projects/site/assets/'
37๐
I know it is an old post but this solution has worked for me and might help someone else.
In settings.py:
if DEBUG:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-Users in initial data fixture
- [Django]-Django aggregate or annotate
28๐
I faced same error like this (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
when i try to use compressor
Main problem is My settings.py file
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
Remove or comment :
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
- [Django]-In the Django admin interface, is there a way to duplicate an item?
- [Django]-Django: what is the difference (rel & field)
- [Django]-How to create a Django FloatField with maximum and minimum limits?
4๐
The solution is that the STATIC_ROOT must not be set if you are running the Django development server:
import sys
if sys.argv[1] != 'runserver':
STATIC_ROOT = os.path.join(BASE_DIR, "static")
Tested with Django 2.1 in a Windows 10 development environment and in an Ubuntu 18.04 docker container on AWS in a production environment.
- [Django]-How to fix " AttributeError at /api/doc 'AutoSchema' object has no attribute 'get_link' " error in Django
- [Django]-Django testing model with ImageField
- [Django]-How to make email field unique in model User from contrib.auth in Django
0๐
in settings.py set static root to virtual environment so that it collects the static files to folder static_in_env
STATIC_ROOT=os.path.join(VENV_PATH,'static_in_env/')
- [Django]-Django AutoField with primary_key vs default pk
- [Django]-Django filter queryset __in for *every* item in list
- [Django]-Can django's auth_user.username be varchar(75)? How could that be done?
0๐
You have to enter complete path of static directory:
STATIC_ROOT = '/home/reza/blog/static/'
Or If you want to use Collects the static files into STATIC_ROOT by django-admin collectstatic
command you have to use :
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
- [Django]-How do I create multiple model instances with Django Rest Framework?
- [Django]-Programmatically create a django group with permissions
- [Django]-Django form: what is the best way to modify posted data before validating?
0๐
I had this problem in pythonanywhere, added:
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATIC_ROOT = '/home/user/project/'
Then run:
python3.9 manage.py collectstatic
It kind of worked, but sent the files in the main directoryโฆ
- [Django]-Django annotation with nested filter
- [Django]-Comma separated lists in django templates
- [Django]-Django โ convert a list back to a queryset
0๐
For pythonaywhere:
1 โ Add your static root in the setting.py
2 โ Update manually the path environment into web app configuration
- [Django]-Error: [ngModel:datefmt] Expected `2015-05-29T19:06:16.693209Z` to be a date โ Angular
- [Django]-Parsing unicode input using python json.loads
- [Django]-How do I deploy Django on AWS?
0๐
I got the same error below:
The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
Because I set the same folder static
to STATIC_ROOT and STATICFILES_DIRS as shown below:
# "settings.py"
STATIC_ROOT = 'static/'
STATICFILES_DIRS = [
BASE_DIR / 'static/'
]
So, I set the different folder staticfiles
to STATIC_ROOT
as shown below, then the error was solved:
# "settings.py"
STATIC_ROOT = 'staticfiles/' # Here
STATICFILES_DIRS = [
BASE_DIR / 'static/'
]
- [Django]-Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'
- [Django]-Implementing Single Sign On (SSO) using Django
- [Django]-Row level permissions in django
-3๐
saw this in Django 1.11 documentation
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Once you make changes to the urls.py as shown above, it should work fine.
- [Django]-Distributed task queues (Ex. Celery) vs crontab scripts
- [Django]-CSRF validation does not work on Django using HTTPS
- [Django]-How to run Django's test database only in memory?