整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

40行python代码,搭建一个网站并实现用户登陆功

40行python代码,搭建一个网站并实现用户登陆功能(附源码下载)

站登陆是很常用的功能,如果你希望进行用户管理,对不同用户区别显示不同内容,那么就必然使用用户登陆功能。

python开发的网站实现用户登陆非常简单,尤其是使用flask的开发。

本例是用flask实现的一个简单实例:用最简单的代码实现网站登陆的基本功能。文末附源码下载方法,你可以进一步修改实现自己需要的各种功能。

一、效果演示

本例中:同样的一个页面,如果未登陆的用访问显示的是花花草草图片,页面下方显示登陆对话框。但是用户登陆状态下访问同样的页面见到的是美女图片,下方的登陆对话框也变成了登出按钮。

二、Flask目录结构

三、关键代码

本例代码简单,python代码40行左右实现了全部功能,基于这样的模式,你可以进一步修改实现各种需要的功能,例如开发一个公司主页,让未登录的访客只能看到对外宣传文档,一旦用户登陆为员工则提供内部文件和消息显示。 如此等等... ...

四、完整代码下载

完整的演示代码,包括目录结构和html文件模板打包,已经上传在百度盘。请加关注后用私信发送"20180303"字样,系统会自动在私信中回复您下载地址。

请及时关注头条号“有只狗狗叫多多”,后续将介绍python更多参考代码,稍做修改即能使用,学习python不要错过哦。。。。

个登录界面可能有一点点。。。[黑线]

源码放着了,要自己拿去吧[奸笑]


<!DOCTYPE html>

<html>

<head>

<title>Login Page</title>

<style>

body {

background-color: #000;

color: #fff;

text-align: center;

padding-top: 100px;

font-family: 'Courier New', Courier, monospace;

}


h1 {

font-size: 50px;

margin-bottom: 30px;

color: #ff0000;

text-shadow: 0 0 10px #ff0000;

}


table {

margin: 0 auto;

width: 400px;

}


th,

td {

padding: 10px;

}


input[type="text"],

input[type="date"] {

width: 300px;

padding: 5px;

border-radius: 5px;

border: 1px solid #ff0000;

background-color: #000;

color: #ff0000;

}


input[type="submit"] {

margin-top: 20px;

padding: 10px;

background-color: #ff0000;

color: #fff;

border: none;

border-radius: 5px;

cursor: pointer;

transition: background-color 0.3s ease;

animation: pulseEffect 1s infinite;

}


input[type="submit"]:hover {

background-color: #ff6666;

animation: none;

}


.success-message {

margin-top: 30px;

display: none;

animation: fadeInEffect 2s;

}


.checkbox-option {

margin-top: 20px;

animation: slideInEffect 2s;

}


.contact-info {

margin-top: 40px;

animation: bounceEffect 1.5s infinite;

}


/* Animations */

@keyframes pulseEffect {

0% {

transform: scale(1);

}


50% {

transform: scale(1.2);

}


100% {

transform: scale(1);

}

}


@keyframes fadeInEffect {

from {

opacity: 0;

}

to {

opacity: 1;

}

}


@keyframes slideInEffect {

from {

transform: translateX(-100%);

}

to {

transform: translateX(0);

}

}


@keyframes bounceEffect {

0%,

100% {

transform: scale(1);

}

50% {

transform: scale(1.2);

}

}

</style>

<script>

window.onload=function () {

document.querySelector('form').addEventListener('submit', function (event) {

event.preventDefault();

var successMessage=document.getElementById('successMessage');

successMessage.style.display='block';

successMessage.style.animation='fadeInEffect 2s forwards';


var submitButton=document.getElementById('submitButton');

submitButton.disabled=true;

});


document.getElementById('closeButton').addEventListener('click', function () {

var successMessage=document.getElementById('successMessage');

successMessage.style.display='none';

});

}

</script>

</head>

<body>

<h1>死亡协议</h1>

<form>

<table>

<tr>

<th>受害者姓名</th>

<td><input type="text"></td>

</tr>

<tr>

<th>身份证号码</th>

<td><input type="text"></td>

</tr>

<tr>

<th>iphone</th>

<td><input type="text"></td>

</tr>

<tr>

<th>邮箱</th>

<td><input type="text"></td>

</tr>

<tr>

<th>预定日期</th>

<td><input type="date"></td>

</tr>

</table>

<input id="submitButton" type="submit" value="签署协议">

</form>

<div id="successMessage" class="success-message">

<p>最近自杀人数较多,可能会延期</p>

<button id="closeButton">关闭</button>

</div>

<div class="checkbox-option">

<input type="checkbox" id="agreementCheckbox">

<label for="agreementCheckbox">我同意所有要求</label>

</div>

<div class="contact-info">

<p>客服:LHTZ173@163.com</p>

</div>

</body>

果图:

效果图

div + css 实现登录界面,用到的知识点:

  • 表单、h、div、input标签的使用
  • 行内元素和块级元素的区别
  • css类选择器和标签选择器
  • 字体属性,包括大小、颜色、对齐等
  • border的使用
  • padding和margin的使用

实现代码 :