Flask

Some initial material on Flask. Homepage here.

  1. Flask is a python library which allows python code to generate HTML, sent to a browser as a dynamic web page.
  2. The interface between Python and the web service is called WSGI, Web Server Gateway Interface. (Which is a bit myopic, given how many ways there are to do that.)
  3. Flask installed on your computer comes with a small test web server that implements WSGI and will serve your pages to localhost.
  4. Sandbox has the Apache WSGI module installed and will serve pages from the virtual hosts, sandbox-vNN.
  5. You each one one of those virtual hosts on Sandbox, and can install pages there.
    1. When your program works locally, copy it to your home area on Sandbox. (Don't use local_html for the Python code.)
    2. Use the (local) shell command pubswgi to publish your app on the server.
      [bennet@sandbox flask]$ pubwsgi Create a WSGI link under virtual host sandbox-vNN to an existing Flask app in the current directory. pubwsgi vNN modname [ appname ] linkname" For module which includes a specific app. App name defaults to module name. pubwsgi vNN moddir @factory linkname For a module which contains an app factory. [bennet@sandbox flask]$ pubwsgi v01 howdy.py hi WSGI server for v01 reset URL: http://sandbox-v01.mc.edu/app/hi
      Use your own vNN value.
    3. The command just makes a stub that calls your code.
    4. Flask/python code runs as the owner (you) rather than apache, as PHP does. That means your script can read or clobber any of your own files if it has a bug. And can be run by strangers.
  6. Your code is an “app”, which is a Python module. Python modules can be single files or full directories.
  7. The Flash route method essentially binds URLs to methods.
  8. The method is run and returns HTML which is delivered to the browser.
  9. It is usual to generate the HTML using a templating system, but it is not required.
  10. If no method matches the URL, Flask returns an HTTP error to the browser.
  11. Static content (often css, js, or images) is served by the Flash test server from the directory static next to your app.
  12. Apache has been jiggered to serve all static content from /var/virthost/vNN/documents, so you can copy them there to make the posting behave like the test.