Python打发无聊时光:9.使用flask框架创建简易科幻风网页

        为了方便大家移植,我把HTML与CSS直接嵌入到一个py文件,若还需增加一些交互性,可以使用JavaScript来添加动态行为。

一、装flask库

在终端输入:

pip install flask

二、复制代码

from flask import Flask, Response

app = Flask(__name__)

@app.route('/')
def home():
    html = """
    <html>
    <head>
    <title>秦岚之家</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');

        body {
            background-color: #101010;
            color: #33ff49;
            font-family: 'Orbitron', sans-serif;
            margin: 0;
            padding: 0;
            text-align: center;
            overflow: hidden;
        }
        .container {
            max-width: 1200px;
            margin: auto;
            padding: 20px;
        }
        h1 {
            font-size: 4em;
            margin: 0.67em 0;
            animation: neon 1.5s ease-in-out infinite alternate;
            text-shadow: 0 0 5px #33ff49, 0 0 10px #33ff49; /* Updated text-shadow */
        }
        p {
            font-size: 1.5em;
        }
        footer {
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100%;
            background-color: #0c0c0c;
            color: white;
            text-align: center;
            padding: 10px 0;
        }
        #welcomeButton {
            margin-top: 20px;
            padding: 10px 20px;
            font-size: 1.2em;
            background-color: #1c1c1c;
            border: none;
            border-radius: 5px;
            color: #33ff49;
            cursor: pointer;
            transition: background-color 0.3s;
            animation: pulse 2s infinite;
        }
        #welcomeButton:hover {
            background-color: #262626;
        }
        #welcomeText {
            display: none;
            transition: opacity 0.5s;
        }
        @keyframes neon {
            from {
                text-shadow: 0 0 3px #33ff49, 0 0 5px #33ff49; /* Updated text-shadow */
            }
            to {
                text-shadow: 0 0 5px #33ff49, 0 0 8px #33ff49; /* Updated text-shadow */
            }
        }
        @keyframes pulse {
            from {
                box-shadow: 0 0 0 0px rgba(51, 255, 73, 0.7);
            }
            to {
                box-shadow: 0 0 0 10px rgba(51, 255, 73, 0);
            }
        }
    </style>
    </head>
    <body>
    <div class="container">
        <h1>赛博朋克4399</h1>
        <button id="welcomeButton">登录</button>
        <p id="welcomeText">欢迎来到秦岚之家。</p>
    </div>
    <footer>
        <p>© 2121 Galactic Federation. All rights reserved.</p>
    </footer>
    <script>
        document.getElementById('welcomeButton').onclick = function() {
            var welcomeText = document.getElementById('welcomeText');
            welcomeText.style.display = welcomeText.style.display === 'block' ? 'none' : 'block';
            welcomeText.style.opacity = welcomeText.style.opacity === '1' ? '0' : '1';
        };
    </script>
    </body>
    </html>
    """
    return Response(html, mimetype='text/html')

if __name__ == '__main__':
    app.run(debug=True)

三、运行结果

首先点击运行,运行窗口会输出一个网址:

直接点击该网站或复制到浏览器打开:

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值