ผลต่างระหว่างรุ่นของ "Fcamp:การรับอินพุตจาก form"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(หน้าที่ถูกสร้างด้วย '== views.py == <pre> from django.shortcuts import render_to_response from random import sample, randint def index(request): notice =…')
(ไม่แตกต่าง)

รุ่นแก้ไขเมื่อ 07:25, 25 ตุลาคม 2553

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 })