使用Flasger库在Python中大摇大摆地更改基本URL

2024-09-28 23:26:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将RESTAPI的Swagger基本URL从“/”更新为“/testapp”

这是我的招摇配置

swagger_config = {
    "headers": [
    ],
    "specs": [
        {
            "endpoint": 'APISpecification',
            "route": '/APISpecification',
            "rule_filter": lambda rule: True,  # all in
            "model_filter": lambda tag: True,  # all in
        }
    ],
    "static_url_path": "/flasgger_static",
    "specs_route": "/swagger_doc/",
}

根据配置,我可以访问位于127.0.0.1:4444/swagger_doc的招摇过市页面

我想把它改成127.0.0.1:4444/testapp/swagger_doc

我已经尝试在这个配置中使用basePath作为/testapp。不起作用

问题是127.0.0.1:4444/swagger_doc需要一些在127.0.0.1:4444/flasgger_static/内的.js和.css文件,这些文件应该更改为127.0.0.1:4444/testapp/flasgger_static/


Tags: 文件lambdaintruedocswaggerstaticall
1条回答
网友
1楼 · 发布于 2024-09-28 23:26:26

您应该在swagger_config中添加"url_prefix": "/testapp"

swagger_config = {
    "headers": [
    ],
    "specs": [
        {
            "endpoint": 'APISpecification',
            "route": '/APISpecification',
            "rule_filter": lambda rule: True,  # all in
            "model_filter": lambda tag: True,  # all in
        }
    ],
    "static_url_path": "/flasgger_static",
    "specs_route": "/swagger_doc/",
    "url_prefix": "/testapp"
}

相关问题 更多 >