总访问量: AmazingCounters.com

django添加静态文件

  最近做了一个todolist webapp,需要稍微添加css时候又忘记django的添加方法了,查看了以前的项目才想起来,所以记录一下.

  1.settings.py 将以下代码放到最下面

1
2
3
4
5
6
7
8
9
10
STATIC_URL = '/static/'
 
STATICFILES_DIRS =
    os.path.join(BASE_DIR),
)
 
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

  2.给html添加静态文件要点

首行加入,一定要放在首行~

1
{% load staticfiles %}  

然后按照jinjia2或者djagno template的语法加上css等静态文件的路径

1
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />

搞定~  

 

欣赏下最近做的todolist工具~

 

 

 

源码地址:https://github.com/fankcoder/ShowMeTheCode/tree/master/s24/todo

欢迎在github上fork我的代码一起优化~

本文原创欢迎转载,转载请注明原地址:http://www.cnblogs.com/frankcoder/p/5145614.html

posted @ 2016-01-20 16:17  三秋  阅读(1694)  评论(1)    收藏  举报
总访问量: AmazingCounters.com
点击右上角即可分享
微信分享提示