why my django admin site does not have the css style

后端 未结 19 1944
南笙
南笙 2020-12-02 07:49

I make a Django admin site using Django development version

But it does not have a CSS style :

\"alt

19条回答
  •  情歌与酒
    2020-12-02 08:23

    In /project_name/project_name/settings.py you need to set STATIC_URL to tell your site what url to use for static files.

    Then set STATIC_ROOT to be some folder on your filesystem that is not the same as any of your directories listed in STATICFILES_DIRS list.

    Once STATICFILES_ROOT is set, you would run python manage.py collectstatic from the project directory.

    This will copy all the admin static files and all files in any other folders listed in the STATICFILES_DIRS list. Basically this puts all your static files in one place so you you can move them to your CDN when deploying your site. If you are like me and don't have a CDN, then you have two options:

    1. Add the folder you set as STATIC_ROOT to the STATICFILES_DIRS list. This will allow the staticfiles finders in django to locate all the static files.
    2. Move the entire folder of static files somewhere else on your file system and direct STATICFILES_DIRS to include that new location.

    I make no comments about security with this answer, it is just the way I have been able to develop with my web server for small projects. I expect that you will want a CDN as django suggest if you are doing anything larger scale.

    UPDATE: I just ran into this issue and this method didn't quite do what I think you want. What ended up working for me was after I ran collectstatic I just copied the admin static files that it put into STATICFILES_ROOT into the directory that I had used for my own static files. That solved the issue for me.

提交回复
热议问题