简体   繁体   English

为什么我可以导入mako而不是mako.Template?

[英]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). 我正在尝试在Python 3中将Mako与我的Twisted网络服务器一起使用。我有一个虚拟环境,安装了Mako(通过pip)。 I am able to import the Mako package, but not the Template class. 我可以导入Mako包,但不能导入Template类。 Here is the shell output from successfully importing the mako module, and then failing to import its Template class: 这是成功导入mako模块,然后未能导入其Template类的shell输出:

>>> 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. 检查站点程序包中的模块可以发现确实存在一个template.py脚本,其中包含Template类,因此安装中不会缺少它。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Template is defined in mako.template Templatemako.template定义

Thus you should use: 因此,您应该使用:

from mako.template import Template

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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