Django加載靜態網頁模板
步驟:
第一步:在子系統blog根目錄下新建模版目錄templates,里面新建一個login.html
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3個meta標簽*必須*放在最前面,任何其他內容都*必須*跟隨其后! --> <meta name="description" content=""> <meta name="author" content=""> <title>Login</title> <!--引入本地css & js--> <link rel="stylesheet" href="../static/style/app.css" /> </head> <body> <form class="form-horizontal"> <div class="control-group"> <label class="control-label" contenteditable="true" for="inputEmail">郵箱</label> <div class="controls"> <input id="inputEmail" placeholder="Email" type="text" /> </div> </div> <div class="control-group"> <label class="control-label" contenteditable="true" for="inputPassword">密碼</label> <div class="controls"> <input id="inputPassword" placeholder="Password" type="password" /> </div> </div> <div class="control-group"> <div class="controls"> <label class="checkbox" contenteditable="true"> <input type="checkbox" /> Remember me </label> <button class="btn" contenteditable="true" type="submit">登陸</button> </div> </div> </form> </body> </html>
第二步:在blog的views.py添加方法(render()方法是加載網頁模版):
from django.shortcuts import render #Login def login_on(request): return render(request,"login.html")
第三步:更改主工程mysite目錄下的路由設置setting.py:
from django.conf.urls import * from django.contrib import admin from blog import views urlpatterns = [ url('admin/', admin.site.urls), url(r'^login',views.login_on), ]
第四步:訪問http://127.0.0.1:8000/login