我是靠谱客的博主 清新鸵鸟,这篇文章主要介绍Python-Django 项目模块-使用自定义管理应用-注销(十三)Python-django 自定义模块开发前言 一、自定义登录注销,现在分享给大家,希望可以做个参考。
Python-django 自定义模块开发
第四章 Django 自定义模块-使用自定义用户管理模块进行应用管理
前言
本系列文章以一个简单的学校项目来做演示,项目中遇到的问题会一一记录下来,仅供学习参考使用
此处学习版本 python3.8 django 4.0.6 bootstrap3 开发工具 VSCODE
一、自定义登录注销
首先需要配置登录后成功的页面
<!-- 右侧 -->
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li><a href="#"><span ></span>欢迎您:{{ user.username }} </a></li>
<li><a href="{% url 'school_web_users:register' %}"><span class="glyphicon glyphicon-user"></span> 注册</a></li>
<li><a href="{% url 'school_web_users:logout' %}"><span class="glyphicon glyphicon-off"></span> 退出</a></li>
{% else %}
<script type="text/javascript">
window.location.href="{% url 'school_web_users:login' %}";
</script>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> 登录</a></li>
{% endif %}
</ul>
配置注销界面:logged_out.html
{% load i18n static %}
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- 静态地址引入方式-->
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="/static/bootstrap-3.4.1/css/bootstrap.min.css" />
<!-- 程序引入方式 -->
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link rel="stylesheet" href="{% static 'bootstrap-3.4.1/css/bootstrap-theme.min.css' %}" />
<link rel="stylesheet" href="{% static 'laydate-v5.3.1/theme/default/laydate.css' %}" />
<script src="{% static 'js/jquery-3.2.1/jquery.min.js' %}"></script>
<script src="{% static 'js/popper-1.15.0/umd/popper.min.js' %}"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="{% static 'bootstrap-3.4.1/js/bootstrap.min.js' %}"></script>
<script src="{% static 'laydate-v5.3.1/laydate.js' %}"></script>
<!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询(media queries)功能 -->
<!-- 警告:通过 file:// 协议(就是直接将 html 页面拖拽到浏览器中)访问页面时 Respond.js 不起作用 -->
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!--[if lt IE 9]>
<script src="/static/js/html5shiv-3.7.0/html5shiv.js"></script>
<script src="/static/js/respond-1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container-fluid">
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
<!-- 导航栏固定在顶部-->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- 左侧 -->
<div class="navbar-header">
<!--图标 -->
<a class="navbar-brand" href="{% url 'school_web_grade:index'%}" style="padding-top:5px;">
<img alt="Brand" src="/static/images/ico.png">
</a>
<a class="navbar-brand" href="{% url 'school_web_grade:index'%}">陕西家里蹲大学师生信息管理系统</a>
</div>
</div>
</nav>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row" style="padding-top: 50px;padding-bottom: 50px;">
<div class="panel panel-info ">
<div class="panel-heading">注销登录</div>
<div class="panel-body ">
title: {{title }}
site : {{site }}
site_name : {{site_name }}
<script type="text/javascript">
window.location.href="{% url 'school_web_users:login' %}";
</script>
</div>
</div>
</div>
<div class="row navbar navbar-default navbar-fixed-bottom" style="text-align: center; height: 40px;">
<div class="bg-success" style="height: 100% ;padding-top: 15px;">
版权所有@copyRight 2013-2022 口袋里的小龙 开发框架 python3.8 bootstrap-3 Django4
</div>
</div>
</div>
</body>
</html>
解释:
school_web_users:logout 为指定注销用户登录的方法 logout 默认使用系统的登录注销的方法,
window.location.href="{% url 'school_web_users:login' %}"; 为自动从logged_out.html跳转到登录界面,默认点击退出按钮是跳转到logged_out.html中 此处需要注意
最后
以上就是清新鸵鸟最近收集整理的关于Python-Django 项目模块-使用自定义管理应用-注销(十三)Python-django 自定义模块开发前言 一、自定义登录注销的全部内容,更多相关Python-Django内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复