Django 无法从python 3.6中的其他包导入模块
我想从player.views.py文件中的gameplay软件包导入models.py文件,但出现错误: 没有名为游戏的模块。游戏性 我已经试过了:Django 无法从python 3.6中的其他包导入模块,django,python-3.x,Django,Python 3.x,我想从player.views.py文件中的gameplay软件包导入models.py文件,但出现错误: 没有名为游戏的模块。游戏性 我已经试过了: from game.gameplay.models import Game from ..gameplay.models import Game 我的项目结构如下: project | | |--game(package) | | | |--gameplay(package) | | | | | |--__init__.
from game.gameplay.models import Game
from ..gameplay.models import Game
我的项目结构如下:
project
|
|
|--game(package)
| |
| |--gameplay(package)
| | |
| | |--__init__.py
| | |--models.py
| |
| |--player(package)
| | |
| | |--__init__.py
| | |--views.py
| |
| |--manage.py
|
|--venv
您是否在设置中添加了应用程序
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# if it is on the manage.py level (appname)
'gameplay',
# in a module (module.appname)
'game.gameplay'
]
验证应用程序的名称(如果它位于manage.py级别)
对于模块,必须进行指定,以便正确编译python。例如(在模块中)
如果正确,您应该能够使用导入(如果在manage.py级别)
(在模块中)
看起来您设置了错误的
PYTHON\u路径
。PYTHON\u路径有多错误?如果是错误的python路径,那么正确的路径是什么,您能告诉我吗?您的应用程序与manage.py处于同一级别吗?或者在模块内。我也有同样的问题。如果是这种情况,则通过在安装“game.gameplay”中指定它来解决
from django.apps import AppConfig
class GameplayConfig(AppConfig):
name = 'gameplay'
from django.apps import AppConfig
class GameplayConfig(AppConfig):
name = 'game.gameplay'
def ready(self):
# example importing signals
import game.gameplay.signals # noqa
from gameplay.models import Game
from game.gameplay.models import Game