Static files of django admin page are not loaded

I just installed tailwind css for my project through this link in Django and used it in my templates and there was no problem. But now I realized that the admin panel has a problem and all its static files are not loaded and receive a 404 error.



I also tried python manage.py collectstatic command, but I got this message and it didn’t work: 0 static files copied to '...\core\static'

settings.py:

DEBUG = True


TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / 'templates'],
        "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",
            ],
        },
    },
]


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "static"
STATICFILES_DIRS = [BASE_DIR / "staticfiles"]

# Configure compressor

COMPRESS_ROOT = BASE_DIR / 'staticfiles'

COMPRESS_ENABLED = True

STATICFILES_FINDERS = ('compressor.finders.CompressorFinder',)

urls.py:

urlpatterns = [
    path("admin/", admin.site.urls),
]

# Serving static and media for development
if settings.DEBUG:
    urlpatterns += static(
        settings.STATIC_URL, document_root=settings.STATIC_ROOT
    )

That link is telling you to use the static file finder

STATICFILES_FINDERS = ('compressor.finders.CompressorFinder',)

And in the templates, to add

{% load compress %}

This is all fine, but of course the admin templates do not have that load in them by default, because compress is a seperate package.

You have a couple of options.

Option 1

Add the “usual” static files finders back in as defined in the django docs. Though I’m not sure what compress will do with these - it’s possible that they will break the regular stuff then

[
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
]

But usually django processes things in order, so if you put your compressor finder in at the top of the list, I would hope it would be fine.

Option 2

Override the default admin template to add the load compressor line in, so that it can use the compressor finder.

Side note: I have no idea if compressor works with app dirs as I’ve not seen that package before, so you may need to run collectstatic.