Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading