AttributeError:类型对象“用户”没有属性“名称”

编程入门 行业动态 更新时间:2024-10-26 07:38:43
本文介绍了AttributeError:类型对象“用户”没有属性“名称”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是石墨烯的新手,我有这个:

I’m new with graphene and I have this:

from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User

基本上,使用Django的User类会给我这个错误,因为在使用django User类之前,我使用了自己的User定义并且可以正常工作。为什么使用django身份验证框架中的User类会给我标题中提到的错误:

Basically, using Django’s User class is giving me this error, because before using the django User class, I was using my own User definition and it worked. Why using the User class from the django authentication framework is giving me the error mentioned in the title:

File / usr / local / lib /python3.6/site-packages/graphql/type/typemap.py中,行中的,如果map中的type.name:AttributeError:类型对象'User'没有属性'name '

File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 60, in reducer if type.name in map: AttributeError: type object ‘User’ has no attribute ‘name’

我错过了什么吗?

问候

PD:我正在使用Django 2.0.4 跟踪

PD: I’m using Django 2.0.4 Traceback

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x107c49e18> Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run self.check(display_num_errors=True) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check include_deployment_checks=include_deployment_checks, File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks return checks.run_checks(**kwargs) File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks new_errors = check(app_configs=app_configs) File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 397, in check for pattern in self.url_patterns: File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 536, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 529, in urlconf_module return import_module(self.urlconf_name) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/freddy/PycharmProjects/DYD/DYD/urls.py", line 19, in <module> from dyd_server.graphql import schema File "/Users/freddy/PycharmProjects/DYD/dyd_server/graphql/__init__.py", line 10, in <module> schema = graphene.Schema(query=RootQuery, mutation=Mutations) File "/usr/local/lib/python3.6/site-packages/graphene/types/schema.py", line 57, in __init__ self.build_typemap() File "/usr/local/lib/python3.6/site-packages/graphene/types/schema.py", line 123, in build_typemap schema=self File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 69, in __init__ super(TypeMap, self).__init__(types) File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 16, in __init__ self.update(reduce(self.reducer, types, OrderedDict())) File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 77, in reducer return self.graphene_reducer(map, type) File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 107, in graphene_reducer return GraphQLTypeMap.reducer(map, internal_type) File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 80, in reducer field_map = type.fields File "/usr/local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 16, in __get__ value = obj.__dict__[self.func.__name__] = self.func(obj) File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 180, in fields return define_field_map(self, self._fields) File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 189, in define_field_map field_map = field_map() File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 250, in construct_fields_for_type map = self.reducer(map, field.type) File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 77, in reducer return self.graphene_reducer(map, type) File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 107, in graphene_reducer return GraphQLTypeMap.reducer(map, internal_type) File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 80, in reducer field_map = type.fields File "/usr/local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 16, in __get__ value = obj.__dict__[self.func.__name__] = self.func(obj) File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 180, in fields return define_field_map(self, self._fields) File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 189, in define_field_map field_map = field_map() File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 250, in construct_fields_for_type map = self.reducer(map, field.type) File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 78, in reducer return GraphQLTypeMap.reducer(map, type) File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 60, in reducer if type.name in map: AttributeError: type object 'User' has no attribute 'name'

推荐答案

这是一个隐式错误,当意外使用Django Model类时发生在代码中而不是石墨烯类型类。例如,确保您的查询类似于

This is a cryptic error that happens when Django Model classes are accidentally used in code instead of graphene Type classes. For example, make sure that your query is something like

user = graphene.Field(UserType)

而不是

user = graphene.Field(User)

更多推荐

AttributeError:类型对象“用户”没有属性“名称”

本文发布于:2023-10-22 08:15:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   对象   名称   类型   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!