(转)Django ====> 实战学习篇四 引入bootstrap,设置静态资源
2012-09-25 11:17
567 查看
按照迭代开发的计划,下一步是美化界面,引入bootstrap 显示如下风格:
为了实现这个界面,在设计初期我们自己定义静态资源,包括imge,css,js等等,(django正式部署的时候对静态资源有特殊的处理,开发阶段我们以简单的方式让静态资源起到作用)。
在project目录下建立static目录,将静态资源按合理的方式放入其中:
回到django 我们进行如下设置(仅仅在开发阶段)
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 )
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 看到设计好的界面
原作者提供的源代码下载
让后就可以我们自己修改模板,美化产品清单页的样式了。
为了实现这个界面,在设计初期我们自己定义静态资源,包括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 看到设计好的界面
原作者提供的源代码下载
让后就可以我们自己修改模板,美化产品清单页的样式了。
相关文章推荐
- Django实战(5):引入bootstrap,设置静态资源
- Django实战(5):引入bootstrap,设置静态资源
- go实战(5):引入bootstrap,设置静态资源
- 引入bootstrap,设置静态资源
- Django ====> 1.4版本静态文件路径设置--MEDIA_ROOT,MEDIA_URL, STATIC_ROOT, STATIC_URL学习
- Django学习笔记(1)---引入静态资源
- (转)Django ====> 实战学习篇八 增加目录页,设置统一布局
- (转)Django ====> 实战学习篇十 让页面联动起来
- (转)Django ====> 实战学习篇一 django印象
- (转)Django ====> 实战学习篇五 模板系统说明
- (转)Django ====> 实战学习篇七 Model类的修改
- Django ====> 1.4版本静态文件路径设置--MEDIA_ROOT,MEDIA_URL, STATIC_ROOT, STATIC_URL学习
- (转)Django ====> 实战学习篇十一 Django实现RESTFul web service,Django+jquery,ajax
- SpringBoot学习历程(3)->springboot中对静态资源的访问
- (转)Django ====> 实战学习篇二 需求分析及设计,创建第一个模型---购物车的应用
- Django学习___静态资源访问
- django学习之引入bootstrap
- (转)Django ====> 实战学习篇三 MODEL之外需要知道的
- ThinkPHP5学习笔记(3)-静态公共资源的引入
- 深度学习21天实战caffe学习笔记《17:学习资源>