Django加载静态网页模板

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

原文地址:https://www.cnblogs.com/lizm166/p/9414399.html