继续django学习之旅,之前我们所做的Django练习前端都非常丑。这节我们使用Bootstrap,顿时使丑陋的页面变成白天鹅。
?
安装Bootstrap??????????????????????????????????????
Bootstrap是什么?
Bootstrap是Twitter推出的一个用于前端开发的开源工具包。它由Twitter的设计师Mark?Otto和Jacob?Thornton合作开发,是一个CSS/HTML框架。Bootstrap提供了优雅的HTML和CSS规范,它即是由动态CSS语言Less写成。
?
django-bootstrap-toolkit
django-bootstrap-toolkit应用可以让Django非容易的集成Bootstrap。
?
安装django-bootstrap-toolkit
?
>pip install django-bootstrap-toolkit
运行bootstrap例子???????????????????????????????????
?
克隆django-bootstrap-toolkit?项目
https://github.com/dyve/django-bootstrap-toolkit
?
$ git clone git://github.com/dyve/django-bootstrap-toolkit.git
??
克隆下来的django-bootstrap-toolkit?项目自带demo_project,现在我们可以直接运行这个demo了。
进入demo_project?目录运行:
> python manage.py runserver
通过浏览器访问:http://127.0.0.1:8000/
wa?o?!!?cool?比我们之前的djngo例子好看多了。
?
预览demo_project???????????????????????????????????????????????????????????????????????
来看一下这个项目的结构吧!
通过前面多个django项目练习,我们已经对这个目录结构不陌生了。下面看看这个例子要特别注意的:
settings.py
…… INSTALLED_APPS = ( 'django.contrib.auth',django.contrib.contenttypesdjango.contrib.sessionsdjango.contrib.sitesdjango.contrib.messagesdjango.contrib.staticfiles# Uncomment the next line to enable the admin: 'django.contrib.admin', Uncomment the next line to enable admin documentation: 'django.contrib.admindocs', bootstrap_toolkitdemo_app',) ……
要想使用bootstrap,这里必须加载bootstrap_toolkit?,demo_app则是我们当前的项目。
urls.py
from django.conf.urls import patterns,url Uncomment the next two lines to enable the admin: # from django.contrib import admin admin.autodiscover() from django.views.generic import TemplateView urlpatterns = patterns('',0); line-height:1.5!important"> Examples: url(r'^$','demo_project.views.home',name='home'),0); line-height:1.5!important"> url(r'^demo_project/',include('demo_project.foo.urls')), Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/',include('django.contrib.admindocs.urls')),0); line-height:1.5!important"> url(r'^admin/',include(admin.site.urls)), url(r^$',TemplateView.as_view(template_name=index.html'),name="home"),url(r^contact$contact.htmlcontact^form$demo_app.views.demo_form'),0); line-height:1.5!important">^form_template$demo_app.views.demo_form_with_template^form_inline$demo_app.views.demo_form_inline^formset$demo_app.views.demo_formsetformset^tabs$demo_app.views.demo_tabstabs^pagination$demo_app.views.demo_paginationpagination^widgets$demo_app.views.demo_widgetswidgets^buttons$buttons.htmlbuttons