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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南