天天看点

python django添加静态资源

在setting中确认以下:

<code>STATIC_URL </code><code>=</code> <code>'/static/'</code>

将静态目录放到app下,在app中创建static目录,然后再创建css、js、image。

在html中添加静态资源的路径:   

<code>{% load staticfiles %}</code>

<code>&lt;</code><code>link</code> <code>rel</code><code>=</code><code>"stylesheet"</code> <code>href</code><code>=</code><code>"{% static 'css/main.css' %}"</code> <code>/&gt;</code>

载入图片的方式和以上差不多,只要把static目录添加就好:

本文转自 王家东哥 51CTO博客,原文链接:http://blog.51cto.com/xiaodongge/1949662