flask
This is probably just the right size framework, very basic but extendable with plug ins.
installation
This library depends on other libraries like werkzeug(wsgi) and jinja2(templates). Virtualenv is another tool that is not required but handy for python in general. It creates a separated environment for python in which you can install all packages you need. So you can mix python versions for instance for different projects. An example of how to use :
| install | |
|---|---|
You should source (.) the activate script not execute it.
routing
This is done by werkzeug, and is simply done by providing a decorator like this:
| routing | |
|---|---|
The trailing slash is subtle but differs in handling comparable to file systems paths, these commands are the same :
That's how it works in the 'directory' form (with '/'), but in the 'file' form (/about) the distinction is :
The second one will fail, and so also gives a 404 error in werkzeug routing.
blueprints
These are almost applications, but they are registered onto an application. They do share the same configuration, also you can register blueprints multiple times on different url's etc
celery
A small warning portion about celery, which is a quit extensive task queue. I used this for the maintenance thread of the soc portal but it turned out to be too extensive. Mainly having to start up two extra processes is what turned me off.
However note that when you mix sqlalchemy + Flask + celery :
You can encounter this error, strangely occurring in only the second time a task runs.
Error
OperationalError('(psycopg2.OperationalError) SSL error:
It has to do with forking after opening the database or something but more pragmatic, when you use forking it happens :
| celery | |
|---|---|
When you start it with solo, or even let scheduling everything is fine :
celery beat
Note that if you want the scheduler to run it also needs the beat service and it has to be started in the same directory as the workers, because that's where the configuration is.
| beat | |
|---|---|
Only after you start this command, the workers start to run.