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

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
 
(ไม่แสดง 1 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน)
แถว 1: แถว 1:
 
== views.py ==
 
== views.py ==
  
<pre>
+
<geshi lang="python">
 
from django.shortcuts import render_to_response
 
from django.shortcuts import render_to_response
 
from random import sample, randint
 
from random import sample, randint
แถว 23: แถว 23:
 
'b': b,
 
'b': b,
 
'notice': notice })
 
'notice': notice })
</pre>
+
</geshi>
  
 
== index.html ==
 
== index.html ==
  
<pre>
+
<geshi>
 
{% extends "base.html" %}
 
{% extends "base.html" %}
  
แถว 43: แถว 43:
 
</p>
 
</p>
 
{% endblock %}
 
{% endblock %}
</pre>
+
</geshi>

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

views.py

<geshi lang="python"> 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 }) </geshi>

index.html

<geshi> {% extends "base.html" %}

{% block content %}

Answer this!

แม่แบบ:Notice
<form method="post"> แม่แบบ:A + แม่แบบ:B = <input type="text" name="answer"/> <input type="hidden" name="a" value="แม่แบบ:A"/> <input type="hidden" name="b" value="แม่แบบ:B"/> <input type="submit" value="Go"/> </form>

{% endblock %} </geshi>