Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将自定义模块导入Django_Python_Django - Fatal编程技术网

Python 将自定义模块导入Django

Python 将自定义模块导入Django,python,django,Python,Django,我正在制作django应用程序,无法在views.py文件中导入自定义模块 我正在尝试从integrations/views.py的模块文件夹内的auth.py导入类“Integrate” 我试着将init.py放在app文件夹和modules文件夹中,但仍然不起作用 views.py: from ..modules.auth import Integrate Powershell: from ..modules.auth import Integrate ValueError: Attem

我正在制作django应用程序,无法在views.py文件中导入自定义模块

我正在尝试从integrations/views.py的模块文件夹内的auth.py导入类“Integrate”

我试着将init.py放在app文件夹和modules文件夹中,但仍然不起作用

views.py:

from ..modules.auth import Integrate
Powershell:

from ..modules.auth import Integrate
ValueError: Attempted relative import beyond toplevel package

我在我的项目中经常这样做。创建自定义模块并导入它们

试试这个:

from modules.auth import Integrate
您可以使用以下选项:

from .models import Integrate

这将适用于使用模型

我非常确定我遇到了这个确切的问题。 如果将保存模块的目录设置为“Sources Root”,则会有所帮助 右键单击目录,弹出窗口底部是“将目录标记为”选项。
好吧,这会将该目录添加到PythonPath中,这样就可以找到其中的模块。

可能重复感谢,没有错误,但PyCharm仍然无法识别它。请参见上文@edgar的评论!