Some initial material on Flask.
Homepage
here.
- Flask is a python library which allows python code to generate HTML,
sent to a browser as a dynamic web page.
- 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.)
- Flask installed on your computer comes with a small test web server
that implements WSGI and will serve your pages to localhost.
- Sandbox has the Apache WSGI module installed and will serve pages
from the virtual hosts, sandbox-vNN.
- You each one one of those virtual hosts on Sandbox, and can install
pages there.
- When your program works locally, copy it to your home area on Sandbox.
(Don't use local_html for the Python code.)
- 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.
- The command just makes a stub that calls your code.
- 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.
- Your code is an “app”, which is a Python module. Python modules
can be single files or full directories.
- The Flash route method essentially binds URLs to methods.
- The method is run and returns HTML which is delivered to the browser.
- It is usual to generate the HTML using a templating system, but it is
not required.
- If no method matches the URL, Flask returns an HTTP error to the browser.
- Static content (often css, js, or images) is served by the Flash test
server from the directory static next to your app.
- 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.