当django debug=False时,后台样式丢失问题

当我们配置好静态文件路径时,然后登录后台,后台样式全部丢失了,此时,按照网上解决方案,即执行

python manage.py collectstatic

后,

This will overwrite existing files!
Are you sure you want to do this?

Type yes to continue,&nbs***bsp;no to cancel: yes
发现后台报错 静态文件找不到,无法迁移,这说明我们得静态路径配置错误,python manage.py  collectstatic  无法收集,

这时,我们可以在一下两处稍微改动一下即可:

STATIC_URL = /static/
STATICFILES_DIRS = (os.path.join(BASE_DIR, "/static/"),)
STATIC_ROOT = (os.path.join(BASE_DIR, static).replace(\,/))

将上面信息改成

STATIC_URL = static/
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"),)
STATIC_ROOT = (os.path.join(BASE_DIR, static).replace(\,/))

即可进行

python manage.py collectstatic

命令,然后Type ‘yes’ to continue, or ‘no’ to cancel: yes Found another file with the destination path ‘admin/css/changelists.css’. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.

2061 static files copied to ‘/home/python/Desktop/daima/django/django214/CommunityService/static’, 361 unmodified.

表示后台样式已经转移到我们创建得静态文件中了,最后我们在把之前的静态文件配置改回来即可成功!

STATIC_URL = /static/
STATICFILES_DIRS = (os.path.join(BASE_DIR, "/static/"),)
STATIC_ROOT = (os.path.join(BASE_DIR, static).replace(\,/))

此时就可以看到我们的后台美观界面啦!

经验分享 程序员 微信小程序 职场和发展