'Django I'm trying do perform a simple task, display on the page whatever was input in a textfield
All I want is the user to type in something in a single textfield and have the input displayed on the same page by the form. Please help!!!!
I tried so many solutions nothing seems to work and its such a simple task
please see my code:
views.py
def math_drills(request):
num1 = random.randint(0,100)
num2 = random.randint(0,100)
total = num2 + num1
if request.method == 'POST':
form = Addition(request.POST)
if form.is_valid():
u_i = request.POST['uans']
return redirect('math_drills_url')
return render(request,'math_drills.html',{
'num1':num1,
'num2':num2,
'total':total,
})
html
<div class="col-lg-12">
<script type="text/javascript">
</script>
<label class="" id="num1" name="">{{num1}}</label> +
<label class="" id="num2" name="">{{num2}}</label> =
<form action="" method="post">
{% csrf_token %}
<input id="your_name" type="text" name="uans" value="" id="" style="width:2%;">
<input type="submit" value="add">
</form>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
