Python 如何通过教程解决使用graphene django基本设置时出现的问题?
我已经开始使用Django和GraphQL进行基本设置 但是,由于导入错误,我无法继续:Python 如何通过教程解决使用graphene django基本设置时出现的问题?,python,django,python-import,graphene-python,Python,Django,Python Import,Graphene Python,我已经开始使用Django和GraphQL进行基本设置 但是,由于导入错误,我无法继续: ImportError at /graphql Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. ImportError: No module named schema. Request Method: GET Request URL: http://127.0.0.1:8000/graphql Djang
ImportError at /graphql
Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. ImportError: No module named schema.
Request Method: GET
Request URL: http://127.0.0.1:8000/graphql
Django Version: 1.11.2
Exception Type: ImportError
Exception Value:
Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. ImportError: No module named schema.
Exception Location: /home/mackie/Code/graphene_django_tutorial/env/local/lib/python2.7/site-packages/graphene_django/settings.py in import_from_string, line 78
Python Executable: /home/mackie/Code/graphene_django_tutorial/env/bin/python
Python Version: 2.7.12
Python Path:
['/home/mackie/Code/graphene_django_tutorial/cookbook',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7/plat-x86_64-linux-gnu',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7/lib-tk',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7/lib-old',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/mackie/Code/graphene_django_tutorial/env/local/lib/python2.7/site-packages',
'/home/mackie/Code/graphene_django_tutorial/env/lib/python2.7/site-packages']
Server time: Sun, 4 Jun 2017 16:29:46 +0000
您可以在最小回购中查看代码的当前状态
我认为我的问题与我如何运行服务器有关:python3 manage.py runserver
。或者我是如何导入的。但是我不知道如何从这里进行更多的调试
所有内容都完全如教程中所述,对我来说没有什么特别不正确的地方。如果这很重要的话,我也将Linux与virtualenv一起使用
如果您需要更多信息,请告诉我,我将仔细监视线程
编辑:任命!我用python3和Python2.7运行了它,两者都不起作用。以下是跟踪:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/graphql
Django Version: 1.10.6
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graphene_django',
'ingredients']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
42. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
62. self = cls(**initkwargs)
File "/usr/local/lib/python2.7/dist-packages/graphene_django/views.py" in __init__
70. schema = graphene_settings.SCHEMA
File "/usr/local/lib/python2.7/dist-packages/graphene_django/settings.py" in __getattr__
116. val = perform_import(val, attr)
File "/usr/local/lib/python2.7/dist-packages/graphene_django/settings.py" in perform_import
60. return import_from_string(val, setting_name)
File "/usr/local/lib/python2.7/dist-packages/graphene_django/settings.py" in import_from_string
78. raise ImportError(msg)
Exception Type: ImportError at /graphql
Exception Value: Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. ImportError: No module named schema.
要导入cookbook.schema
,需要将schema.py
放在内部cookbook
目录(包含settings.py
的目录)中。目前,它位于外部cookbook
目录(包含manage.py
)中。要从外部目录导入它,您需要在设置中使用'schema.schema'
当教程说要将'components'
添加到已安装的应用程序设置中(建议它应该在外部cookbook
目录中)时,也会出现类似的混乱,但代码中包括了从cookbook.components.models导入…
(建议配料
应位于内部食谱
目录中)
您可以尝试将schema.py
和components
目录移动到内部cookbook
目录中,并将INSTALLED_APPS
中的条目更改为'cookbook.components'
,如中所示。执行此行
pip install graphene_django
你说你运行
python3 manage.py runserver
是没有意义的,但是错误显示为Python 2.7。你还没有显示完整的回溯,这将显示导入失败的地方。对不起!我在这两种情况下都运行了它,我在原始文章中添加了完整的跟踪。你完全正确,教程中有一些错误的路径,我无法找到请告诉我一个令人疯狂的调试路径。非常感谢!以后任何对本教程有困难的人,请查看repo的这一部分:这个答案的第一部分似乎不正确。我仍然会收到错误,将其引用为“cookbook.schema.schema”,并在内部cookbook d中引用schema.py文件董事会。
pip install graphene_django