'module' object has no attribute 'schema'

Viewed 2105

I have a problem while running some code from the training:

AttributeError: 'module' object has no attribute 'schema'

My schema is stored in schema.py file

Anacoda Navigator, spyder, Python 2.7, W10

import schema

SCHEMA = schema.schema

While running the first file I got a problem:

AttributeError: 'module' object has no attribute 'schema'

Do you have any idea what is wrong here?

2 Answers

I have had the same problem.

The structure of my files are as following:

├── apps
│   ├── schema
│   |   └── schema.py
│   └── users
│       ├── admin.py
│       ├── apps.py
│       ├── __init__.py
│       ├── models.py
│       ├── schema.py
│       ├── tests.py
│       └── views.py
├── db.sqlite3
├── manage.py
└── transportation
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

According to the structure all schemas are located in apps.schema.schema.py file.

Schema.py

import graphene
from graphene import ObjectType

import [some queries from models]

class Query (apps.users.schema, graphene.ObjectType):
    pass


schema = graphene.Schema(query=Query)

There are two ways to resolve this problem.

  1. Go to settings.py files and add this line to it.
GRAPHENE = {
    'SCHEMA': 'apps.schema.schema.schema'
  1. Go to urls.py and add the following line:
from apps.schema.schema import schema
urlpatterns = [
    ...
    path('graphql', GraphQLView.as_view(graphiql=True, schema=schema))
]
Related