title: Simple Calculator using HTML forms in python django
body: <p>Below is my html form:</p>
  
  <pre><code>&lt;form id="calci_form" method="get" action="#"&gt;
   &lt;input type="hidden" name="prev_val" value="{{prev_val}}"&gt;&lt;/input&gt;
   &lt;input type="hidden" name="curr_val" value="{{curr_val}}"&gt;&lt;/input&gt;
   &lt;input type="hidden" name="op_sign" value="{{opsign}}"&gt;&lt;/input&gt;
   &lt;div id="calculator"&gt;
   &lt;table id="tableCalci"&gt;
   &lt;tr  id="row1"&gt;
   &lt;td colspan="4"&gt;&lt;input type="text" value="0" class="display" name="user_input"&gt;{{result}}&lt;/input&gt;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;/tr&gt;
  &lt;tr class="hover"&gt;
  &lt;td&gt;&lt;button id="7" name="numval" value="7" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="8" name="numval" value="8" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="9" name="numval" value="9" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="plus" name="sym" type="submit" value="add"&gt;&amp;plus;&lt;/button&gt;      
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr class="hover"&gt;
  &lt;td&gt;&lt;button id="4" name="numval" value="4" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="5" name="numval" value="5" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="6" name="numval" value="6" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
  &lt;td&gt;&lt;button id="minus" name="sym" value="minus" type="submit"&gt;&amp;minus;   
  &lt;/button&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr class="hover"&gt;
   &lt;td&gt;&lt;button id="1" name="numval" value="1" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
   &lt;td&gt;&lt;button id="2" name="numval" value="2" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
   &lt;td&gt;&lt;button id="3" name="numval" value="3" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
   &lt;td&gt;&lt;button id="times" name="sym" value="times" type="submit"&gt;&amp;times;  
   &lt;/button&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="hover"&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&lt;button id="0" name="numval" value="0" type="submit"&gt;&lt;/button&gt;&lt;/td&gt;
   &lt;td&gt;&lt;button id="equal" name="sym" type="submit"&gt;&amp;equals;&lt;/button&gt;&lt;/td&gt;
   &lt;td&gt;&lt;button id="divide"; name="sym" type="submit" value="divide"&gt;&amp;divide;   
   &lt;/button&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;/table&gt;
   &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Views.py file:</p>
  
  <pre><code>if 'sym' in request.GET:
          if request.GET['sym'] == 'add':
              first=request.GET['result']
              opsign='\&amp;plus;'
              return render(request,'calculator.html',{'result':first,'prev_val':first,'curr_val':second,'opsign':opsign}) 
  elif request.GET['sym'] == '=':
              if 'prev_val' in request.GET and request.GET['prev_val']:
                  first=request.GET['prev_val']
              if 'result' in request.GET and request.GET['result']:
                  second=request.GET['result']    
              try:
                  result=add(10,20)
              except ValueError:
                  err="Error: Incorrect Number"
              except ZeroDivisionError:
                  err="Error: Division by zero"
              return render(request,'calculator.html',{'result':result,'error':err}) 
          else:
              return render(request,'calculator.html',{'error':'No Operation selected'}) 
  </code></pre>
  
  <p>Solution required: When i click the "Plus" button or "Equal" button the above mentioned function does not invoke at all. THe controller is not passed from HTML page to the above function in the views.py file. Where am i making the mistake and why the controller is not passing control to the function. Any help is appreciated.</p>