django don't load static files, on the site when i use f12 i can see that /static/js/.., but styles not work
Template home-page.html
{% load static %}
piece of code and
<!-- JQuery -->
<script type="text/javascript" src="{% static 'app1/js/jquery-3.4.1.min.js' %}"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="{% static 'app1/js/popper.min.js' %}"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="{% static 'app1/js/bootstrap.min.js' %}"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="{% static '../js/mdb.min.js' %}"></script>
<!-- Initializations -->
<script type="text/javascript">
// Animations initialization
new WOW().init();
urls.py
from commercemag import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app1.urls', namespace='item-list')),
]
if settings.DEBUG:
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
it's settings
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')
idk what i should do, please help me
CodePudding user response:
add this in your code
import os
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
CodePudding user response:
try to add this in urls.py but this is only work when we posting any images from templates and stored in static files
urlpatterns = [
path('admin/', admin.site.urls),
] static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
also try this
comment your STATIC_ROOT = os.path.join(BASE_DIR, 'static')
CodePudding user response:
update settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'static')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]