How to Change the Base URL for drf_yasg in Version 1.21.4
To change the base URL for drf_yasg in version 1.21.4, you can use the 'url' parameter when initializing the 'OpenAPIRenderer' and 'SwaggerUIRenderer' classes.
Here's an example:
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from drf_yasg.renderers import OpenAPIRenderer, SwaggerUIRenderer
schema_view = get_schema_view(
openapi.Info(
title='Your API',
default_version='v1',
description='Your API description',
),
public=True,
permission_classes=[permissions.AllowAny],
url='https://your-domain.com/api/', # Set the base URL here
)
urlpatterns = [
path('swagger<format>', schema_view.without_ui(
renderer_classes=[OpenAPIRenderer]
), name='schema-json'),
path('swagger/', schema_view.with_ui(
renderer_classes=[SwaggerUIRenderer]
), name='schema-redoc'),
]
In this example, the 'url' parameter is set to 'https://your-domain.com/api/'. This will be used as the base URL for the API documentation generated by drf_yasg.
Note that you need to set the 'url' parameter for both the 'OpenAPIRenderer' and 'SwaggerUIRenderer' classes if you want the base URL to be changed for both JSON and HTML documentation.
原文地址: https://www.cveoy.top/t/topic/mXuf 著作权归作者所有。请勿转载和采集!