每次按下“提交”时,我都尝试将{{password}}更改为不同的密码。我使用Flask和HTML来做这件事。创建密码的函数是用python编写的。
我尝试在Flask文件中将password设置为空字符串,希望每次按下“Submit”时它都是空的。但是,它没有更改密码。每次按下提交时,我都试图将{{password}}更改为新的{{password}}。
from flask import Blueprint,render_template, request, g
from gen import main
#This is where the different website pages will be implemented with python
views = Blueprint(__name__,'views')
@views.route('/')
def home():
return render_template('home.html')
@views.route('/index.html')
def generator():
return render_template('index.html', password = '')
@views.route("/result", methods=['POST', 'GET'])
def result():
password = ''
return render_template("result.html",password = password + main())
def main():
pword =''
while True:
x = randint(randint(20,30),randint(30,40))
randoml = []
while len(password) < x:
lettersL = letters(alphabet)
numbersL = numbers(alphabet)
symbolsL = symbols(alphabet)
randoml.append((random.choice(lettersL)))
randoml.append((random.choice(numbersL)))
randoml.append((random.choice(symbolsL)))
if len(randoml) > 10000: password.append(random.choice(randoml))
pword = ''.join(password)
return pword
<html>
<head>Generated Password</head>
<body>
<form class = "password" action = "/result" method = "POST">
<center>
{% if password%}
<h3 style="color: rgb(216, 44, 216)">Your password is {{password}}</h3>
{% endif%}
</center>
</form>
<form class = "grid" action = "/result">
<center>
<input type="Submit" class ="file_submit" value="Generate New Password">
{% if password%}
<h3 style="color: rgb(216, 44, 216)"></h3>
{% endif%}
</center>
</form>
</body>
</html>
2条答案
按热度按时间41zrol4v1#
下面是一个更简单、性能更好的生成密码的机制。
输出:
qij5mzcb2#
我不认为你需要在你的main函数上使用一个无限的while True循环。
我会这样做: