我已经开始使用Django和GraphQL完成基本设置的graphene_django tutorial。在
但是,由于导入错误,我无法进一步进行:
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
您可以在一个最小的repo中看到代码here的当前状态。在
我认为我的问题与我如何运行服务器有关:python3 manage.py runserver
。或者我是怎么进口的。但我不知道如何在这里进行更多的调试。在
每件事都和教程里说的一模一样,对我来说没有什么特别不正确的。如果这很重要的话,我也将Linux与virtualenv一起使用。在
如果你需要更多的信息请告诉我,我会仔细监视线程。在
编辑:任命!我用python3和python2.7运行过它,但都不起作用。以下是线索:
^{pr2}$
为了使
cookbook.schema
可导入,您需要将schema.py
放在cookbook
内目录(包含settings.py
的目录)中。目前,它位于外部cookbook
目录(包含manage.py
的目录)。要从外部目录导入它,您需要在设置中使用'schema.schema'
。在当教程说要将
'ingredients'
添加到INSTALLED_APPS
设置(建议它应该在外部cookbook
目录中)时,也有类似的混淆,但是代码中包含了类似于from cookbook.ingredients.models import ...
的导入(建议ingredients
应该在cookbook
目录中)。在您可以尝试将},如this repo。在
schema.py
和ingredients
目录移到内部cookbook
目录中,并将INSTALLED_APPS
中的条目改为{执行此行
相关问题 更多 >
编程相关推荐