帮助我了解此代码的问题。如您所见,它只有两行代码。
from flask import Flask
app = Flask(__name__)
返回TypeError。
C:\Users\Natali\AppData\Local\Enthought\Canopy32\User\lib\site-packages\flask\app.pyc in auto_find_instance_path(self)
620 .. versionadded:: 0.8
621 """
--> 622 prefix, package_path = find_package(self.import_name)
623 if prefix is None:
624 return os.path.join(package_path, 'instance')
C:\Users\Natali\AppData\Local\Enthought\Canopy32\User\lib\site-packages\flask\helpers.pyc in find_package(import_name)
659 """
660 root_mod_name = import_name.split('.')[0]
--> 661 loader = pkgutil.get_loader(root_mod_name)
662 if loader is None or import_name == '__main__':
663 # import name is not found, or interactive/main module
C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.3.0.1715.win-x86\lib\pkgutil.pyc in get_loader(module_or_name)
462 else:
463 fullname = module_or_name
--> 464 return find_loader(fullname)
465
466 def find_loader(fullname):
C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.3.0.1715.win-x86\lib\pkgutil.pyc in find_loader(fullname)
473 """
474 for importer in iter_importers(fullname):
--> 475 loader = importer.find_module(fullname)
476 if loader is not None:
477 return loader
TypeError: find_module() takes exactly 3 arguments (2 given)
很抱歉有很长的错误代码。 知道为什么会这样吗?
答案 0 :(得分:2)
您需要先将代码保存在文件中,然后从命令行运行它。只需在交互式提示中输入即可。
这是最小的Flask应用程序的样子:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World'
if __name__ == '__main__':
app.run()
将此代码保存到文件(例如server.py
),然后使用python server.py
运行。