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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值