【发布时间】:2021-11-13 09:21:25
【问题描述】:
我想做一个信用卡生成器,生成格式为 (number|exp.month|exp.year|cvv) 的信用卡,信用卡号遵循 luhn 算法。用户输入一个 BIN(银行识别号),我使用 python 生成一个十六位数字的信用卡。我将所有信用卡存储在python变量output中,但是当我尝试使用jinja2函数{{ output }}在html页面上显示它时,它不会在html页面上显示。
我很确定 Python 代码的所有 html 代码以及数学和循环部分都是正确的。
当我尝试使用时
def function1:
return (output)
它没有显示错误,并显示了所需的输出。但我希望它在 HTML 文件本身中,而不是在新的单独页面上加载。
索引.html:
<!DOCTYPE html>
<html>
<head>
<title>
Home
</title>
</head>
<body>
<h1>
Fire CC Generator
</h1>
<form action="{{ url_for("function1") }}" method="post">
<label for="Bin">B.I.N.</label>
<input type="text" name="Bin" placeholder="Enter BIN"><br>
<input type="text" name="quantity" placeholder="Enter Quantity"><br>
<button type="button" value="Submit">
</form>
<p>
Output: {{output}}
</p>
</body>
</html>
index.py:
import random
from flask import Flask, render_template, request, url_for
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def function1():
if request.method == 'POST':
# getting input with name = Bin in HTML form
Bin = request.form.get('Bin')
# getting input with name = lname in HTML form
quantity = int(request.form.get('quantity'))
x = 0
ccnum = 0
good = 16 - len(Bin)
output = ''
exp_month_list = [
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'10',
'11',
'12',
]
while x != quantity:
r = str(random.randint(pow(10, good - 1), pow(10, good)- 1))
iccnum = Bin + r
# Luhn Algorithm Begins
def luhn_checksum(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
checksum = 0
checksum += sum(odd_digits)
for d in even_digits:
checksum += sum(digits_of(d * 2))
return checksum % 10
# Luhn Algorithm Ends
if luhn_checksum(int(iccnum)) == 0:
ccnum = iccnum
ccnum = str(ccnum)
exp_month = random.choice(exp_month_list)
exp_year = str(random.randint(2022, 2026))
cvv = str(random.randint(100, 999))
CC = str(ccnum + '|' + exp_month + '|' + exp_year + '|'+ cvv + '\n')
output += CC
x += 1
else:
x = x
return render_template('index.html', output=output)
return render_template('index.html')
if __name__ == '__main__':
app.run()
GitHub 存储库链接:https://github.com/FieryKing01/Python-CC-generator
【问题讨论】:
-
我永远离开了jinga。现在我什至不知道如何拼写它。 Jinga是浪费时间。我应该只是学习 JS。