Answer the question
In order to leave comments, you need to log in
Has anyone experienced that statics are not displayed in Django 3.2 (but sometimes they are)?
Came across something wonderful in Django 3.2... No static from some directories inside static
in dev mode... Nearly all except /static/admin/
. I don't understand anything. In settings.py
everything as usual, the same with other projects in which everything works:
from my_project.my_secret import MY_MEDIA_ROOT_DEV1, MY_STATIC_ROOT_DEV1
MEDIA_ROOT = MY_MEDIA_ROOT_DEV1
STATIC_ROOT = MY_STATIC_ROOT_DEV1
STATIC_BASE_PATH = STATIC_ROOT
# STATICFILES_DIRS = [
# # MY_STATIC_ROOT_DEV1,
# # Put strings here, like "/home/html/static" or "C:/www/django/static".
# # Always use forward slashes, even on Windows.
# # Don't forget to use absolute paths, not relative paths.
# # BASE_DIR,
# MY_STATIC_ROOT_DEV1 + '/js',
# MY_STATIC_ROOT_DEV1 + '/img',
# MY_STATIC_ROOT_DEV1 + '/webfonts',
# MY_STATIC_ROOT_DEV1 + '/css',
# MY_STATIC_ROOT_DEV1 + '/svgs',
# ]
url.py
the same way as in other projects:from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf.urls import url
from my_project import settings
from web import views
urlpatterns = [
path('a-d-m-i-n/', admin.site.urls),
url(r'^$', views.index),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
python manage.py collectstatic
all the static, as expected, it is collected in the static / admin directory and any of these files can be viewed. Like : 127.0.0.1:8000/static/admin/css/base.css ... but no files from other files are shown ! .py or not... And whether or not there is a line urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) in url.py ... And, what is especially strange, if any file is put in the static/ folder admin or there static/admin/js -- this file is also NOT DISPLAYED. Sees only the files that he draggedpython manage.py collectstatic
... What kind of magic is this?
Answer the question
In order to leave comments, you need to log in
Honestly, I didn’t quite understand the code, but:
settings.py
STATIC_URL = "/staticfiles/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static_files")]
if bool(settings.DEBUG):
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question