python - 如何解决“无法为石墨烯设置'SCHEMA'导入'todo.schema.schema'。AttributeError:模块'graphene'没有属性'string'。”?
问题描述
我创建了 Django 石墨烯项目。突然我收到一个错误,无法为石墨烯设置“SCHEMA”导入“todo.schema.schema”。AttributeError:模块“石墨烯”没有属性“字符串”。但我不知道如何解决它。
我的架构结构是: todo/schema/schema
设置.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# third party app
'graphene_django',
'django_filters',
]
GRAPHENE = {
'SCHEMA': 'todo.schema.schema'
}
主要网址.py:
urlpatterns = [
path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
架构.py:
class Query(TodoQuery, graphene.ObjectType):
pass
class Mutation(Mutation, graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)
应用程序架构.py:
# declar todo model field
class TodoType(DjangoObjectType):
class Meta:
model = TodoList
fields = ('id', 'title', 'date', 'text')
# declar user model filed
class UserType(DjangoObjectType):
class Meta:
model = User
# todo list query
class TodoQuery(graphene.ObjectType):
todoList = DjangoListField(TodoType)
def resolve_todoList(root, info):
return TodoList.objects.filter(userId=2)
# create todo
class TodoCreate(graphene.Mutation):
class Arguments:
title = graphene.String(Required=True)
text = graphene.string(Required=True)
todo = graphene.Field(TodoType)
def mutate(root, info, title, text):
# userId = info.context.user
user = User.objects.get(id=2)
todo = TodoList(userId=user, title=title, text=text)
todo.save()
return TodoCreate(todo=todo)
# todo mutation
class Mutation(graphene.ObjectType):
createTodo = TodoCreate.Field()
我错过了什么?或者我做错了什么?
解决方案
你有一个错字text = graphene.string(Required=True)
。它还在错误中说石墨烯没有属性字符串。它区分大小写,应该是text = graphene.String(Required=True)
你可以为你的编辑器使用一个 linter,这样你将来就可以捕捉到这样的小东西。
推荐阅读
- flutter - 致命例外:主要?
- c# - EF6 如何为 DevExpress LookupEdit 获取数据
- c# - 如何在特定文件夹中写入图像
- sql - 带有 row_number 的 MySQL 连接子句
- javascript - 使用带有条件的Javascript提交表单,必须按两次提交
- python - 如何更改 x-tick 标签以仅显示日期时间对象的天数?
- postman - 跟踪页面的访问者数量
- javascript - Lat/Long 掩码正/负检测
- python - 在 Python 脚本中存储用户设置
- mongodb - Mongo Shell 在连接到 AWS Document DB 后变得无响应