的Python /瓶/ HTML的Python /瓶/ HTML和随机随机长度变量输出
代码下面我有没有两件事情我想实现:
1)生成随机lenght输出随机choosen,以前定义变量列表并在html中显示它。
例如(输出):
苹果橙
苹果
苹果橙橘
我不不过要为水果中产生的输出重复,保持一切,因为它是。
所以我想从发生
怎样才可以实现禁止
“苹果橙橘”
?下面
代码:
app.py
from flask import Flask, render_template
import os
import random
app = Flask(__name__)
@app.route('/')
def main():
z=randint(1, 4)
Hash1="apple"
Hash2="orange"
Hash3="banana"
Hash4="watermelon"
fruits = [Hash1, Hash2,Hash3, Hash4]
a=[choice(fruits) for x in range(z)]
a=a
return render_template ('show.html', a=a)
if __name__ == '__main__':
app.run(host=os.getenv('IP', '0.0.0.0'),port=int(os.getenv('PORT', 8080)))
show.html
<html>
<title>App</title>
</head>
<body>
<h2>your fruits are {{ a }} </h2>
</body>
</html>