为什么昂首阔步引发不清楚的错误-Django [英] why swagger raises unclear error - Django

查看:157
本文介绍了为什么昂首阔步引发不清楚的错误-Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django rest后端应用程序,我用招摇工具向FE查找和记录我的api。

I have a django rest Backend app, and i use swagger to look and document my apis to the FE.

这工作正常,但我进行了一些更改,但现在出现此错误:

This worked fine, but I made some changes and now I get this error:

Internal Server Error: /
Traceback (most recent call last):
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 497, in dispatch
    response = self.handle_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 457, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 468, in raise_uncaught_exception
    raise exc
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 494, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework_swagger/views.py", line 32, in get
    schema = generator.get_schema(request=request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 153, in get_schema
    links = self.get_links(None if public else request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 140, in get_links
    link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: 'AutoSchema' object has no attribute 'get_link'
HTTP GET / 500 [0.15, 127.0.0.1:44214]
/home/notsoshabby/Desktop/panda_pitch/django_project/settings.py 

这个错误不是很明显toSchema不是我的代码的一部分,并且回溯并没有显示问题出在我的代码中。
我进行了太多更改,无法一一检查并确定是哪一个引起的。

This error is not very clear as the AutoSchema is not a part of my code and the traceback is not showing me where in My code the problem is. I made too many changes to go one by one and check which one caused that.

有人遇到过此问题吗?关于如何调试以查找导致此问题的更改的任何想法?

Anyone experienced this issue before? Any ideas on how to debug to find which change causes this issue?

推荐答案

我遇到了相同的问题,此处描述了解决方法: https://www.django-rest-framework.org/community/3.10-announcement/

I ran into the same issue, the fix is described here: https://www.django-rest-framework.org/community/3.10-announcement/

总而言之,Django Rest Framework 3.10(日前发布)已弃用基于CoreAPI的架构,并在其位置引入了OpenAPI架构。当前要继续使用django-rest-swagger,您需要通过在设置文件中添加以下配置来重新启用CoreAPI模式生成:

To summarize, Django Rest Framework 3.10 (released a few days ago) deprecated the CoreAPI based schema generation, and introduced the OpenAPI schema generation in its place. Currently to continue to use django-rest-swagger as is you need to re-enable the CoreAPI schema generation by adding the following config to the settings file:

REST_FRAMEWORK = { ... 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }

这篇关于为什么昂首阔步引发不清楚的错误-Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆