django The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting - django

I'm deploying a Django application on heroku.
In my settings module, I have configured to host static files like
STATIC_ROOT = os.path.join(BASE_DIR, 'static_my_project')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static_my_project')
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn', 'media_root')
and urls.py
urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
But on deployment to heroku, it gives error as
SystemCheckError: System check identified some issues:
ERRORS:
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.

may be help this.
STATIC_URL = '/static/'
if not DEBUG:
STATIC_ROOT = ''
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/'),
]

The problem is in the STATIC_ROOT and STATICFILES_DIRS there names cant be same.
static root is used for collectstatic command of django.
You can remove it if not using it.
And can also remove static files dirs if not changing its default position(inside django app) to somewhere else like base or something.

Related

In django-admin statics not loading /static/admin/css/base.css not found

urlpatterns = [some_urls] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
statics configured
DEBUG = TRUE
python manage.py collectstatic did 1000 times
cache cleared
I have no idea what to do, can anyone help me please

Django 3.2.8: 0 static files copied to '/static'

This error occurs when performing command python manage.py collectstatic:
0 static files copied to '/home/project'.
That means there is no changes and my static files already exist in the destination but in this folder only one file:
static/
- staticfiles.json
But I want all my CSS, js, HTML for panel admin to be in it.
Django Settings:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
STATICFILES_DIRS = (
STATIC_ROOT,
)
urls.py
...
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I also tried these 1, 2 but no results were found.
settings.py
import os
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
urls.py
urlpatterns = [
path('demo/',Demo.as_view(),name='demo')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.STATIC_ROOT)
Add Your File in folder-
static->demo_folder->staticfiles.json
python3 manage.py collecstatic
Define all paths with STATICFILES_DIRS where Django will look for static files.
For example:
STATICFILES_DIRS = [os.path.join(BASE_DIR, "templates/staticfiles")]
When you run collectstatic, Django will copy all found files in all your paths from STATICFILES_DIRS into STATIC_ROOT.
In your case, Django will copy all files to:
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
After that, your static files are accessible through your defined STATIC_URL URL. In your case:
STATIC_URL = '/static/'

Gunicorn cant find the static files

By using gunicorn without nginx from digitalcloud tutorial
my server is runing and on the console is
not found: /static/style.css
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
I already tried to
collectstatic
do urlpatterns += staticfiles_urlpatterns() in urls.py file
makemigrations + migrate
maybe django try read 'static//static/style.css' but you need this: 'style.css' ;) ?
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
urlpatterns = [your urls here] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
You can create in your project folder settings then in them create settings files like names:
local.py
from my_project.settings import *
DEBUG = True
ALLOWED_HOSTS = []
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
this run in VM like: python manage.py runserver --settings settings.local
remember in urls add:
if settings.DEBUG == True:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
web.py
from my_project.settings import *
DEBUG = False
ALLOWED_HOSTS = ["www.side.com", "side.com"]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
and then in gunicorn import only web.py file project to read in nginx
this run in VPS server.

Is there a way to add my django-tenant schema name to MEDIA_ROOT?

I have modified my Geonode project, which is a GeoDjango project, to enable multi-tenancy using django-tenants. I am currently not able to view my thumbnails due to broken routing...
How do I correctly route my generated thumbnails like this: http://d3.demo.com(current_tenant_domain_url)/uploaded/d3(tenant)/thumbs/document-8a72dc8c-0151-11eb-a488-1062e5032d68-thumb.png
The thubnail url that is currently generated is as follows: http://localhost:8000/uploaded/thumbs/document-fcdea3a4-015c-11eb-a488-1062e5032d68-thumb.png?v=c1855f6a
urls.py
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.LOCAL_MEDIA_URL,
document_root=settings.MEDIA_ROOT)
My current settings.py
MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(PROJECT_ROOT, MEDIAFILES_LOCATION))
MEDIA_URL = os.getenv('MEDIA_URL', '%s/%s/%s/' % (FORCE_SCRIPT_NAME, MEDIAFILES_LOCATION, MULTITENANT_RELATIVE_MEDIA_ROOT))
Any help will be appreciated
settings.py
MIDDLEWARE = [
'django_tenants.middleware.main.TenantMainMiddleware'
]
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = 'django_tenants.files.storages.TenantFileSystemStorage'
MEDIA_ROOT = os.path.join(BASE_DIR, 'public', 'media')
urls.py
urlpatterns = [...] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Django staticfiles_dirs not working correctly

I'm working with this website http://fotokluczniok.pl/ now.
If You press F12 You will see the staticfiles do not work correctly.
Here is my seetings.py code:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
'/home/fotoklu/fotokluczniok/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
Here is urls.py code:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Project structure: CLICK HERE
How to solve this problem ?
I think you don't need to change something about the static files in the urls.py file. And also delete the variable STATIC_ROOT. In general your code in Settings.py file:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join (BASE_DIR, 'static'),
]
I also had this problem. It helped me.
NOTE: Always restart the server after changes in settings.py