twistd
方法启动Klein服务器。一世
通过阅读Klein documentation。以下是我尝试过的示例代码,
helloworld.py:
from klein import Klein
from klein import resource, route
app = Klein()
@route('/')
def hello(request):
return "Hello, world!"
然后我运行以下命令:
twistd -n web --class=helloworld.resource
我收到以下错误:
File "C:\Python27\lib\site-packages\twisted\python\reflect.py", line 165, in namedObject
module = namedModule('.'.join(classSplit[:-1]))
File "C:\Python27\lib\site-packages\twisted\python\reflect.py", line 151, in namedModule
topLevel = __import__(name)
ImportError: No module named helloworld
答案 0 :(得分:0)
将包含helloworld.py
的目录放入导入路径。例如,将其添加到PYTHONPATH
:
$ PYTHONPATH=${PWD} twistd -n web --class=helloworld.resource