6 <:import:>

<:import name [items] [as]:>

Imports a Python code module into the STML template. This is practically identical to the import statement in Python.

If the items parameter is specified, it should be either '*' or, a space delimited list of names in the module to copy into the STML template's namespace. If items is '*', all names in the module (that don't begin with '_') are copied into the STML template's namespace.

If the as parameter is specified, it acts just like the as clause to the Python import statement. Some examples, with their equivalents in straight Python:

<:import string:>
import string
<:import string find:>
from string import find
<:import string "find replace join":>
from string import find, replace, join
<:import string *:>
from string import *
<:import string find string_find:>
from string import find as string_find

Note on where modules come from: When you do an <:import foo:> in STML, the SkunkWeb server first looks for the module foo in Python's standard module directories. If it does not find the module in any of those directories, SkunkWeb then looks in your custom SkunkWeb module library, which is usually /usr/local/skunk/site-libs (but could be changed by modifying sys.path in sw.conf) for a file foo.py. If SkunkWeb still cannot find the module foo, it raises an ImportError.