django-bootstrap第一個登錄頁面

一、請求頁面

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>

參考

現在可以快樂的編寫了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章