我是 Django 和 GraphQL 的初学者,我在第一步遇到问题,我无法访问 GraphiQL,我遇到了错误
Could not import 'traindjango.schema.schema' for Graphene setting 'SCHEMA'.
AttributeError: module 'graphene' has no attribute 'Heroes'.
traindjango/heroes/schema.py
import graphene
from graphene_django import DjangoObjectType
from .models import Heroes
class HeroesType(DjangoObjectType):
class Meta:
model = Heroes
class Query(graphene.ObjectType):
heroes = graphene.Heroes(HeroesType)
def resolve_links(self, info, **kwargs):
return Heroes.objects.all()
traindjango/traindjango/schema.py
import graphene
import heroes.schema
class Query(heroes.schema.Query, graphene.ObjectType):
pass
schema = graphene.Schema(query=Query)
traindjango/traindjango/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'heroes',
'graphene_django',
]
GRAPHENE = {
'SCHEMA' : 'traindjango.schema.schema',
}
traindjango/heroes/models.py
from django.db import models
class Heroes(models.Model):
name = models.CharField(max_length=100, verbose_name='Name')
power = models.IntegerField(default=0)
city = models.TextField(max_length=100, verbose_name='City' ,null=True, blank=True)
你能帮我做什么吗?
非常感谢