I am trying to make {{password}} change to a different password each time ‘submit’ is pressed. I am using Flask with html to do this. The function that creates the password is written in python.
I have tried making password an empty string in the Flask file expecting it to be empty each time ‘Submit’ is pressed. However, it did not change the password. I am trying to change {{password}} to a new {{password}} each time submit is pressed.
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
Answers
I don’t think you need an infinite while True loop on your main function.
Here is how I would do it:
Here is a much simpler and better performing mechanism for generating a password.
Output: