一、请求页面
render_to_response(‘login.html’)
对于请求一个页面时,在相对应的views同文件目录下创建一个templates文件,在里面放入login.html.如图:
在settings.py TEMPLATE_DIRS里面添加对应的路径:
二、django-bootstrap搭建
1.安装django-bootstrap-static
pip install django-bootstrap-static
安装成功后会在python/site-packages目录下增加一个bootstrap目录
2.settings.py中引入
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.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',**
)
3、改变引用路径static
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.min.css"/>
4、然后就可以引用里面的内容了
login.html代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>登录</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.min.css"/>
</head>
<body>
<h1 class="page-header">登 录</h1>
<form action="" method="post" class="form-horizontal">
<div class="form-group" >
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="请输入用户名/email"/>
</div>
</div>
<div class="form-group" >
<div class="col-sm-5">
<input type="password" class="form-control" placeholder="请输入密码"/>
</div>
</div>
<div class="form-group" >
<div class="col-sm-5">
<button class="btn-primary">登 录</button>
</div>
</div>
</form>
</body>
</html>
现在可以快乐的编写了!