Fcamp:การรับอินพุตจาก form
รุ่นแก้ไขเมื่อ 07:25, 25 ตุลาคม 2553 โดย Jittat (คุย | มีส่วนร่วม) (หน้าที่ถูกสร้างด้วย '== views.py == <pre> from django.shortcuts import render_to_response from random import sample, randint def index(request): notice =…')
views.py
from django.shortcuts import render_to_response
from random import sample, randint
def index(request):
notice = ''
if request.method == 'POST':
a = int(request.POST['a'])
b = int(request.POST['b'])
answer = int(request.POST['answer'])
if a+b == answer:
notice = 'Correct answer'
else:
notice = 'Sorry, please try again'
else:
a = randint(1,100)
b = randint(1,100)
return render_to_response("index.html",
{ 'a': a,
'b': b,
'notice': notice })