DEBUG=False下,static静态文件引用方法

问题特征:

django网站中的静态文件CSS、Image在本地服务器使用runserver指令可以完美加载,部署到IIS上后CSS失效、静态文件消失的问题

方法来源:

StackOverFlow


解决步骤:

①在项目的具体app路径下的static文件夹(settings中STATIC_URL指定的目录),新建web.config文件,注意不要弄错目录,是app中存放静态文件的目录下

DEBUG=False下,static静态文件引用方法

DEBUG=False下,static静态文件引用方法


web.config内容如下:

[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <configuration>  
  3.   <system.webServer>  
  4.     <!-- this configuration overrides the FastCGI handler to let IIS serve the static files -->  
  5.     <handlers>  
  6.     <clear/>  
  7.       <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />  
  8.     </handlers>  
  9.   </system.webServer>  
  10. </configuration>  


② 打开IIS管理器,选定该网站项目,右击选择添加虚拟路径

DEBUG=False下,static静态文件引用方法


③ 填写虚拟路径的别名和路径,别名一般为static,路径则是该网页app下的static文件夹,也就是刚才创建web.config的文件夹

DEBUG=False下,static静态文件引用方法


⑤ 重新运行一下IIS,应该就没有问题了


转自:http://blog.****.net/qq_18075613/article/details/56970016