[英]the module is not recognized in python (flask)
learning flask and new to web dev here, made the directories as below.在这里学习 flask 和 web 开发新手,制作目录如下。 in folder named website and in a subfoder named templates make a file init _.py and outside the website folder,main.py is there
在名为 website 的文件夹和名为 templates 的子文件夹中创建一个文件init _.py 并在 website 文件夹之外,main.py 在那里
code in init .py init .py 中的代码
from flask import Flask
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY']='madkrish'
return app
code in main.py main.py 中的代码
from website import create_app
app = create_app()
if __name__== '__main__':
app.run(debug=True)
When i run the main function the following errors comes:当我运行主 function 时出现以下错误:
No Module named 'website'没有名为“网站”的模块
Can someone please correct me where i am wrong i need to go further in the tutorial to the next step.有人可以纠正我哪里错了我需要在教程中进一步的 go 到下一步。
From your folder structure, you need to import from templates, so:从您的文件夹结构中,您需要从模板导入,因此:
from templates import create_app
It should works.它应该有效。
VSCode will still marks it as error, you need to configure it to inlcude your templates folder in the Python Path VSCode 仍会将其标记为错误,您需要将其配置为在 Python 路径中包含您的模板文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.