【问题标题】:Django REST Framework + Django REST SwaggerDjango REST 框架 + Django REST Swagger
【发布时间】:2017-07-06 13:22:05
【问题描述】:

很难配置 Swagger UI 以下是 - https://django-rest-swagger.readthedocs.io/en/latest/ 中非常解释性的文档。我的 settings.py 看起来像这样。

urls.py 看起来像这样。

但是招摇的网页没有正确加载。

控制台日志如下。

这里可能有什么问题?

【问题讨论】:

    标签: python django django-rest-framework swagger django-swagger


    【解决方案1】:

    看看django-rest-swagger schema documentation,那里有一些关于它如何与 DRF 关联的代码示例。您可以通过访问DRF Schema Generator 文档了解更多相关信息。

    如果您只是想在不了解该库的更多信息的情况下启动并运行,article 在展示项目架构以及将 DRS 与 DRF 集成方面做得很好。

    【讨论】:

    • INSTALLED_APPS 中甚至没有 rest_framework
    【解决方案2】:

    首先,将 django rest 框架安装到您的应用程序中,并将其导入到 setting.py 文件中

    使用 DRF 制作一些 API,然后在您的 setting.py 文件中添加 swagger 设置

    SWAGGER_SETTINGS = {
       'SECURITY_DEFINITIONS': {
        'api_key': {
            'type': 'apiKey',
            'in': 'header',
            'name': 'Authorization'
        }
    },  # setting to pass token in header
    'USE_SESSION_AUTH': False,
    # set to True if session based authentication needed
    'JSON_EDITOR': True,
    'api_path': 'api/',
    'api_version': 'v0',
    
    "is_authenticated": False,  # Set to True to enforce user authentication,
    "is_superuser": False,  # Set to True to enforce admin only access
    'unauthenticated_user': 'django.contrib.auth.models.AnonymousUser',
    # unauthenticated user will be shown as Anonymous user in swagger UI.
    

    }

    注意:- 您可以根据需要编辑 swagger 设置。

    【讨论】:

      猜你喜欢
      • 2016-08-10
      • 1970-01-01
      • 2018-10-17
      • 2017-04-09
      • 1970-01-01
      • 2015-08-07
      • 2015-01-04
      • 2017-07-07
      • 1970-01-01
      相关资源
      最近更新 更多