【问题标题】:Swagger in Django rest function based api does not show properly on ubuntu server (production)基于 Django REST 功能的 API 中的 Swagger 在 ubuntu 服务器(生产)上无法正确显示
【发布时间】:2017-11-30 06:14:08
【问题描述】:

我无法在 ubuntu django 设置上正确显示我的招摇。我正在使用基于函数的 API,就像这里 https://github.com/m-haziq/django-rest-swagger-docs

这是没有正确显示招摇的结果 - ubuntu 16.04(在 AWS 中)

https://imgur.com/TnTNExa

但是在我的开发环境mac pc上

https://imgur.com/E1Zst0E

这是我的招摇模式。如您所见,我有一些日志记录:

https://gitlab.com/firdausmah/railerdotcom/blob/master/railercomapp/swagger_schema.py

以下是一些日志记录:

2017-11-30 06:06:57,367 DEBUG xxxx home hello
2017-11-30 06:07:25,131 DEBUG get(self, request)
2017-11-30 06:07:25,132 DEBUG Check and load if the function has __doc__
2017-11-30 06:07:25,132 DEBUG swagger try yaml_doc
2017-11-30 06:07:25,134 DEBUG if yaml_doc

我的 Django/NGINX/Ubuntu 设置基于此:

https://jee-appy.blogspot.my/2017/01/deply-django-with-nginx.html

请随意查看我的代码,

https://gitlab.com/firdausmah/railerdotcom/tree/master

swagger 可能有什么问题?在开发它的工作。我设置开发和生产的方式没有什么不同。在生产中使用 nginx、gunicorn、supervisor。在 PC 上它在 python manage.py runserver 上运行。

【问题讨论】:

    标签: django ubuntu django-rest-framework swagger gunicorn


    【解决方案1】:

    此错误是因为您的 swagger 静态文件无法访问或位于未知位置。您可以在 (http://railer.com/swagger/) 控制台中看到显示的错误,即:

    要修复错误,请尝试在您的 settings.py 中添加以下行:

    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, "static"),
    )
    

    如果这不起作用,则将您的静态文件目录添加到其中。有关它的更多信息,请查看此答案:

    How to use a remote static file server while developing with django manage.py runserver

    【讨论】:

    • 那是指出的静态文件。我通过 collectstatic 并重新配置 nginx 以指向静态位置来使其工作。 tqvm
    猜你喜欢
    • 2012-05-29
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 2014-09-26
    相关资源
    最近更新 更多