运行环境:

Windows 10 专业版 64位

Python27

Django1.11

Mysql5.7

IIS 10 或 Apache24


丢失CSS样式后的界面:

IIS或Apache部署Django项目时,Admin后台管理CSS样式丢失?

正确加载CSS样式的界面:

IIS或Apache部署Django项目时,Admin后台管理CSS样式丢失?


通过查看器查看源码可以发现CSS文件并不存在于引用路径下

IIS或Apache部署Django项目时,Admin后台管理CSS样式丢失?


找回丢失的CSS样式:

打开项目/settings.py 添加如下内容:

STATIC_ROOT = os.path.join(BASE_DIR, "static")

命令行cd到项目根目录,运行:

python manage.py collectstatic

Admin后台管理所需要的CSS样式就会复制到指定目录下(STATIC_ROOT)


IIS下:

打开项目/urls.py 添加如下内容:

url(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),


Apache下:

在httpd.conf中添加如下内容:

Alias /static "D:\MyProject\DJgo\ZLH\static"
<Directory "D:\MyProject\DJgo\ZLH\static">
    Require all granted
</Directory>

其中D:\MyProject\DJgo\ZLH\static 为STATIC_ROOT对应的路径



相关文章:

  • 2021-08-20
  • 2021-10-06
  • 2022-12-23
  • 2021-04-11
  • 2021-11-18
  • 2021-06-09
  • 2021-11-21
  • 2021-11-21
猜你喜欢
  • 2021-08-01
  • 2021-06-12
  • 2022-12-23
  • 2021-09-19
  • 2021-11-11
  • 2021-08-25
  • 2021-11-22
相关资源
相似解决方案