(转)Django ====> 实战学习篇四 引入bootstrap,设置静态资源

按照迭代开发的计划,下一步是美化界面,引入bootstrap 显示如下风格:

    为了实现这个界面,在设计初期我们自己定义静态资源,包括imge,css,js等等,(django正式部署的时候对静态资源有特殊的处理,开发阶段我们以简单的方式让静态资源起到作用)。

    在project目录下建立static目录,将静态资源按合理的方式放入其中:

static/
    css/
        bootstrap.mim.css           ===>产品清单界面使用的样式表,整个系统都使用这种风格。
    js/
    images/
    productlist.html                 ===> 产品清单静态界面

   回到django 我们进行如下设置(仅仅在开发阶段)

首先修改setting文件中的static files的部分:

65 import os
66 # Additional locations of static files
67 HERE = os.path.join( os.path.dirname(__file__), '../static/')
68 STATICFILES_DIRS = (
69 # Put strings here, like "/home/html/static" or "C:/www/dja ngo/static".
70 # Always use forward slashes, even on Windows.
71 # Don't forget to use absolute paths, not relative paths.
72 HERE,
73 )

然后在urls.py中加入static的url的映射:

24 from django.contrib.staticfiles.urls import staticfiles_urlpatt
erns
25
26 #for development only this will work only DEBUG is True
27 urlpattern += staticfiles_urlpatterns()

   启动server 通过访问http://127.0.0.1:8000/static/productlist.html 看到设计好的界面

   原作者提供的源代码下载

   让后就可以我们自己修改模板,美化产品清单页的样式了。

 

 

 

 

posted @ 2012-09-25 11:17  事件轮询,回不到过去  阅读(580)  评论(0编辑  收藏  举报