[英]Can't import .py file, no module named 'filename' error
I'm trying to import a.py file into another.py file and I get the error No module named 'filename'我正在尝试将 a.py 文件导入到 another.py 文件中,但出现错误 No module named 'filename'
Here's my directory:这是我的目录:
(local files)/app/__init__.py
(local files)/app/routes.py
(local files)/app/errors.py
(local files)/app/forms.py
(local files)/app/apiDnd.py
I'm trying to use apiDnd.py in routes.py我正在尝试在 routes.py 中使用 apiDnd.py
My __init__.py
file:我的
__init__.py
文件:
from flask import Flask
from config import Config
app = Flask(__name__)
app._static_folder = '../static'
app.config.from_object(Config)
from app import routes, errors, apiDnd
My routes.py
file:我的
routes.py
文件:
from flask import render_template, flash, redirect, url_for, jsonify, request, json
from app import app
import apiDnd
Everything works fine without the import apiDnd
line and that's where the error is.没有
import apiDnd
行,一切正常,这就是错误所在。
Replace import apiDnd
in routes.py
with from. import apiDnd
将 routes.py 中的
import apiDnd
routes.py
为from. import apiDnd
from. import apiDnd
. from. import apiDnd
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.