S
S
Shua_inc2019-02-15 23:56:40
Django
Shua_inc, 2019-02-15 23:56:40

Why doesn't Django-CMS see custom CSS/JS?

Django-CMS refuses to see static files in a project's static directory. Those that are created manually - just do not find. And those that were installed with django and django-cms are still taken from ../env/lib/python3.6/site-packages/cms/static/cms/
collectstatic did.
settings.py

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

urls.py
urlpatterns = [
    path('admin/', admin.site.urls),   
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [url(r'^', include('cms.urls')),]

well in the template
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Trainin, 2019-02-16
@Shua_inc

1. Try to accurately specify the BASE_DIR path. I've done it like this:
2. In urls.py try this:

urlpatterns = [
      somethingurls
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Those. bind directly to the variable (mb will help, well, I personally did it, and this is what the django developers themselves recommend)
3. Check for the presence of 'django.contrib.staticfiles' in the INSTALLED_APPS variable in settings.py
4. Also check for the presence of a variable
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

in settings.py
5. Well, and most importantly, do not forget to import the statics into the template)
The web server can also affect this, in order to understand this, try to load the statics on your PC, if possible, you need to configure the web server .
If it doesn't work, write back, we'll think further)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question