简体   繁体   中英

Why can I import mako and not mako.Template?

I am trying to use Mako with my Twisted webserver in Python 3. I have a virtual environment with Mako installed (via pip). I am able to import the Mako package, but not the Template class. Here is the shell output from successfully importing the mako module, and then failing to import its Template class:

>>> import mako 
>>> from mako import Template
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Template'

Checking the module in site-packages reveals that there is indeed a template.py script with a Template class inside of it, so it's not missing from the install.

Any help would be greatly appreciated.

Template is defined in mako.template

Thus you should use:

from mako.template import Template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM