首页 > 编程语言 >python实现抽奖程序

python实现抽奖程序

时间:2022-12-03 18:02:41浏览次数:34  
标签:index 抽奖 hero render python app 程序 Flask 1.0

基本思路:从LOL英雄联盟中取4个英雄作为抽奖对象,用Flask框架搭建模拟抽奖程序。

一、Flask框架的简单应用

二、random 随机模块的简单应用,生成随机整数

三、python完整实例

from flask import Flask, render_template
from random import randint

app = Flask(__name__)

hero = ['黑暗之女', '狂战士', '正义巨像', '卡牌大师']


@app.route('/index')
def index():
return render_template('index.html', hero=hero)


@app.route('/choujiang')
def choujiang():
num = randint(0, len(hero)-1)
return render_template('index.html', hero=hero, h=hero[num])


app.run(debug=True)

四、html文件

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
{{hero}}<br/>
<a href="/choujiang">随机抽取</a></br>
您抽到了:{{h}}
</body>
</html>

python实现抽奖程序_flask

python实现抽奖程序_flask_02

标签:index,抽奖,hero,render,python,app,程序,Flask,1.0
From: https://blog.51cto.com/u_14012524/5908611

相关文章