djangodjango-admindjango-static

Specifying css file for admin


I am trying to change styles for displaying my model in Django Admin:

class ContentAdmin(MyAdmin):
    ...
    
    class Media:
        css = {
            'all': ('css/myadmin.css',)
        }

The file myadmin.css is located in static/css/.

When running locally, the following appears in the console when loading the admin page:

"GET /static/css/myadmin.css HTTP/1.1" 404 1804

It looks like the request is going to the correct location where the file is resides. So, why isn't it found?


Solution

  • If your static folder is not inside one app then you should register it in the settings. Go to your settings.py file and add the next line:

    STATICFILES_DIRS = [BASE_DIR / "static"]
    

    above I'm assuming your static folder is in the root folder of your project. If not, replace "static" for the proper path to your static folder.