大体的流程:python
参考文档django
在项目根目录创建 static 目录,在 app.conf 中指定 static 目录是静态目录浏览器
handlers: - url : /static/(.*) script : /static/$1 - url : /debug/.* script : debug.py - url : /.* script: index.py - expire : .jpg modify 10 years - expire : .swf modify 10 years - expire : .png modify 10 years - expire : .gif modify 10 years - expire : .JPG modify 10 years - expire : .ico modify 10 years
验证: 在新建的 static 目录中拷贝一个图片 1.jpg ,上传发布代码后,在浏览器中访问 ***.duapp.com/static/1.jpg 应该可以显示该图片。app
设置 STATIC_ROOT 部分,这样django在收集静态文件时会把url
SITE_ROOT = os.path.dirname(os.path.abspath(__file__)) SITE_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../')) STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
python manage.py collectstatic