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

Django加载静态网页模板详解程序员

 

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/2540.html

(0)
上一篇 2021年7月16日 00:57
下一篇 2021年7月16日 00:57

相关推荐

发表回复

登录后才能评论