title: Pseudocode for PHP into Tornado/Python
body: <p>I am very used to working with PHP – creating a new .php file, typing in everything, intermixing it with some HTML, include/requiring different .php/.html files etc. </p>
  
  <p>I just started learning to work with Tornado, and I'm having a hard time wrapping my head around the basic principals and constructs Tornado is built off of. </p>
  
  <p>To begin to understand how exactly much of Tornado works (other than, yes, of course, reading their documents), I am trying to take something basic to me in PHP and recreate it in Tornado. </p>
  
  <p>For example, in PHP, I have my <code>index.php</code> page. On that page I have an <code>email</code> input and <code>password</code> input. When the user submits the form, the <code>action</code> is set to <code>login.php</code>, we are sent to <code>login.php</code> where the "login function" is called which authenticates the user. If all is good, the <code>$_SESSION</code> variable is set, and they are logged in. If there is an error, an error message appears on <code>login.php</code></p>
  
  <p>What would be the equivalent "pseudocode" for this in relation to Tornado? </p>
  
  <p>Some basic, highly imperfect python:</p>
  
  <pre><code>import os
  
  import tornado.web
  import tornado.ioloop
  
  root = os.path.dirname(__file__)
  port = 8888
  
  class MainHandler(tornado.web.RequestHandler):
      def get(self):
          self.render("index.html")
  
  class LoginHandler(tornado.web.RequestHandler):
      def get(self):
          self.render("login.html", title="Login to your account!")
  
      def post(self):
          useremail = self.get_argument("useremail", None)
          password = self.get_argument("password", None)
          self.render("login.html", title="Login to your account!")
  
  def main():
      application = tornado.web.Application([
          (r"/", MainHandler),
          (r"/login", LoginHandler),
          (r"/css/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(root, 'css')}),
          (r"/pictures/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(root, 'pictures')}),
      ])
      application.listen(port)
      tornado.ioloop.IOLoop.instance().start()
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Any help on my conversion here is greatly appreciated. It's just a very different way of doing things than I'm used to, and pseudo-code for simple a process like this would definitely help. Anyway, thanks all.</p>