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

在配置Django静态文件路径后,后台样式丢失。执行`python manage.py collectstatic`时出现找不到文件错误。解决方法是调整STATIC_URL、STATICFILES_DIRS和STATIC_ROOT的设置,去掉多余的前导斜杠,并确保路径正确。执行命令后,静态文件被成功转移,后台恢复正常。
摘要由CSDN通过智能技术生成

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

 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('\\','/'))

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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值