我试图保存在mysql数据库中随机生成的代码,但它只保存第一个字符,我尝试了不同的方法,但没有工作。这是我的密码:
try:
error = None
with mysql.connection.cursor() as cursor:
passwordd = ''
if request.method == 'GET' or 'POST':
for n in range(0, 8):
x = random.randint(0, 9)
if x <= 3:
passwordd += str(random.choice('abcdefghijklmnopqrstuvxyz'))
elif x <= 6:
passwordd += str(random.choice('abcffsddddd'))
else:
passwordd += str(random.randrange(0, 9))
return passwordd
sql = "INSERT INTO generatedcode(password) VALUES (%s)"
cursor.execute(sql, (passwordd))
mysql.connection.commit()
1条答案
按热度按时间qxsslcnc1#
以下是解决方法: