火龙信奥
  • 首页
  • 课程
  • 题库
  • 打卡
    • 代码对战
    • 快速对战
  • 题单
  • 团队
  • 荣誉墙
  • 商城
  • 登录 / 注册

Flask实操

作者: 作者的头像   huolong , 时间:2025-07-28 09:11:14 , 所有人可见, 阅读  31

这是主要架构

wdh/
│
├── app.py
└── templates/
    └── index.html
    └── home.html
└── static/
    └── wdh.jpg

app.py

from flask import Flask, render_template,request

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/login', methods=['POST'])
def login():
    name = request.form.get('name')
    pwd = request.form.get('password')

    if name == 'wdh' and pwd == '123456':
        return render_template('index.html')
    else:
        return render_template('home.html', msg='用户名或者密码错误')

    return '收到!'

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8888)


home.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>吴东航的个人主页</title>
</head>
<body>

    <h1>登录页面</h1>
    <img src="/static/wdh.jpg" width="100px" height="100px">
    <label style="color:red">{{msg}}</label>
    <form action="/login" method="post">
        <label>姓名:</label>
        <input type="text" name="name" placeholder="请输入您的大名">
        <label>密码:</label>
        <input type="password" name="password" placeholder="请输入您的密码,至少6位">
        <button type="subumit">点击登录</button>
    </form>

</body>
</html>

index.html

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用 Flask 微信风格页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            margin: 0;
            font-family: "Helvetica Neue", sans-serif;
            background-color: #f0f0f0;
            color: #333;
        }

        .container {
            max-width: 600px;
            margin: 50px auto;
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            padding: 40px;
            box-sizing: border-box;
        }

        .logo {
            display: block;
            margin: 0 auto 20px;
            width: 60px;
            height: 60px;
            background-color: #74c042;
            border-radius: 50%;
            line-height: 60px;
            text-align: center;
            color: white;
            font-weight: bold;
            font-size: 24px;
        }

        h1 {
            text-align: center;
            color: #2e2e2e;
            margin-bottom: 20px;
        }

        p {
            font-size: 16px;
            line-height: 1.6;
            text-align: center;
        }

        .footer {
            text-align: center;
            margin-top: 40px;
            font-size: 14px;
            color: #999;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">个人主页</div>
        <h1>欢迎使用 Flask</h1>
        <p>这是一个模仿微信风格的欢迎页面。你可以继续扩展功能,比如聊天界面、用户登录等。</p>
        <video 
    src="/static/1.1数字三角形模型.mp4" 
    controls   
    loop 
    preload="auto"
    style="width: 100%; max-width: 800px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
    您的浏览器不支持 video 标签。
</video>
    </div>

    <div class="footer">
        &copy; 2025 Flask 微信风格示例
    </div>
</body>
</html>

视频控制标签使用

<video 
    src="/static/111.mp4" 
    controls 
    autoplay 
    muted 
    loop 
    preload="auto"
    style="width: 100%; max-width: 800px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
    您的浏览器不支持 video 标签。
</video>

—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com

©2026加盟我们 | 关于我们 | ACM课程 | 常见问题 | 成果墙 | 评测记录 | 浙ICP备2021013995号
在线画图 | OI WIki | 打字练习
火龙信奥
请输入登录信息


请完成安全验证
验证码底图 滑块
向右拖动滑块完成验证
请输入用户名 / 绑定的手机号码



请输入注册信息(手机号验证码注册)





验证码5分钟有效,60秒内不可重复获取,每日最多3次

微信登录

微信登录二维码

正在生成二维码...

账号已过期,请续期。
去续期

绑定手机号

📱

为了更好地保护您的账号安全,享受完整的平台服务

请您尽快绑定手机号码