Question:
How to specify css file for admin?

Problem:

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.


Suggested blogs:

>Invoking Python script from scons and pass ARGLIST

>Plugins and Presets for Vuejs project

>Python Error Solved: load_associated_files do not load a txt file

>PHP cURL to upload video to azure blob storage

>PHP Error Solved: htaccess problem with an empty string in URL

>Python Error Solved: pg_config executable not found

>Set up Node.js & connect to a MongoDB Database Using Node.js

>Setting up a Cloud Composer environment: Step-by-step guide>Migrate From Haruko To AWS App: 5 Simple Steps


Ritu Singh

Ritu Singh

Submit
0 Answers