title: Python CherryPy Web Programming Structure
body: <p>I usually programmed web application in PHP. For now I am learning using CherryPy framework of Python to do web program. What I am trying to do is to accept a http Get request from user, then using the variables in the query string to do some function, finally I will return the result. But now I think I am being stuck in the programming convention of CherryPY.</p>
  
  <p>I tried to use the  index function to accept the variables post by GET method and then do function as follows: </p>
  
  <pre><code>import cherrypy
  from sqlalchemy import *
  
  from function import function   
  
  class WelcomePage:
  
  
  def index(self,number):
  
      if not number:
          return "failure";
      else:            
          number1=number;
          return ;    
  
  now = datetime.datetime.utcnow();
  code = generateCode();
  finalResult();
  
  def finalResult():
      return code;
  </code></pre>
  
  <p>The above code does not work, it will just end at the return statement of index(self,number) and I cannot continue the other function. I guess I am breaking the object oriented structure of Python style (different from PHP). 
  So is the following is only the proper way to handle the GET input and return after calculation</p>
  
  <pre><code> @cherrypy.exposed
   def index(self,number):
  
    if not number:
      return "failure";
    else:            
      cal = Calculation();
      other =OtherFunction();  
      code=cal.doSomething(number1);    
      final =other.doAnotherThing(code);
      return final;   
  </code></pre>
  
  <p>That is I need to call all other function within index function and then return the result within the index function. Is that the only way to have something to do about the http GET variable (or post). Can I have alternative way to write the code that does not need to call all the function inside the index funcion ( that seems will make the index function so lengthy). Is that a more clean and clear way to finished the processing of the GET variable with different function and then finally return the calculated result? I have tried to google for many days but still can't figure out a good way.</p>