sproblemas with what to load the ccs and js

0

I am working with the web and while I am without an internet connection everything is shown as well but when connecting to the internet the tables lose styles and some things are distorted I am working with datetable.js and I do not know what to do I'm working with django 1.11 .13 I already did a collectstatic and it continues with the same problem that can be. I leave as I have conformed the work in I have 3 templates one is where the base template is that has the javascript and css libraries and in the others the templates of each project, and a static one that is in src / static which is where they are all javascript and ccs

well I have set in settings.py

STATIC_ROOT = 'static/'
STATIC_URL = '/src/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'src/static')]
    
asked by Antonio 11.09.2018 в 21:00
source

1 answer

0

Do the following:

If you are in DEBUG , set the variable STATICFILES_DIRS = ("path / to / static") in your settings.py . It should work only in DEBUG mode.

If you want it to also work in deployment mode, configure the root variable of STATIC_ROOT = ("path / to / static_root") in settings.py . Then, run python manage.py collectstatic and it should also work.

And now, for a better understanding of how django handles static files:

  • Django has some predefined places to search files static and collect them; you specify where to find them with STATICFILES_FINDERS in your settings.py . By default, look for the static folder within your applications. You can tell Django that look for static files in other parts by configuring the variable STATICFILES_DIRS (list or route tuple).

  • In DEBUG mode, static files are selected from these paths (not static_root where the files are collected).

  • When you run python manage.py collectstatic , Django goes through all the directories where static files are located and places them in your static root. When running in deployment mode, static files are served from this directory.

PD: What I usually do is create an application called common and create a static directory inside to put all the css, js common for my project (and also for the templates). This way, I do not have to specify the variable STATICFILES_DIRS .

Source

This is a solution for static / media / template access in django for windows :

settings.py

import os.path

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = ( os.path.join('static'), )
    
answered by 11.09.2018 / 21:30
source