Здесь только функция Random_number работает правильно, но функция случайного пароля не дает даже вывода на консоль. Я хочу вернуть сгенерированный пароль в шаблон HTML.Есть ли какие-либо проблемы с кодом?
Просмотры
def random_number(request):
random_num = ''
if(request.POST.get('Submit-Number')):
min_number = int(request.POST.get('min_number'))
max_number = int(request.POST.get('max_number'))
random_num = random.randint(min_number,max_number)
return render(request,'random_number/random-number.html'),
{'random_num':random_num})
def random_password(request):
random_pass = ''
if(request.POST.get('Get-Password')):
min_length = int(request.POST.get('min_length'))
#max_length = int(request.POST.get('max_length'))
all_char = 'abcdefghijklmnopqrstuvwxyz123456789!@#$%^&*()'
for eve in range(min_length):
new_word += random.choice(all_char)
random_pass = new_word
print(random_pass)
return render(request,'random_number/random-number.html',
{'random_pass':random_pass})
Шаблоны
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">1</div>
<h3> Generate Random Number Here </h3>
<form class="" action="#" method="POST"> <!-- method is posting and
refreshing page with new Data over Random Number -->
<input type="number" name="min_number" value="1">
<input type="number" name="max_number" value="10">
{% csrf_token %}
<input type="submit" name="Submit-Number" value="SUBMIT">
</form>
<!-- <h3> Random Number = {{ random_num }}</h3> -->
</div>
<div class="col-md-6">2</div>
<h3> Generate Random Password Here </h3>
<form class="" action="#" method="POST"> <!-- method is posting and
refreshing page with new Data over Random Number -->
<input type="number" name="min_length" value="8">
<input type="number" name="max_length" value="12">
{% csrf_token %}
<input type="submit" name="Get-Password" value="SUBMIT">
</form>
<h3> Password = {{ random_pass }}</h3>
</div>
</div>