πŸ“ λ¬Έμ„œν™” (Documents) IN Django

LEE EUI JOOΒ·2023λ…„ 2μ›” 6일
0

Web Programming

λͺ©λ‘ 보기
9/17
post-custom-banner

drf-yasg

  • λ¬Έμ„œν™”λ₯Ό λ„μ™€μ£ΌλŠ” 라이브러리

  • drf-yasg 라이브러리λ₯Ό μ„€μΉ˜

$ pip install drf-yasg
  • drf-yasg 앱을 등둝
    • settings.py 파일 μˆ˜μ •

  • url μ„€μ • - urls.py
from django.contrib import admin
from django.urls import path

from django.contrib import admin
from django.urls import path, include, re_path
from django.conf import settings
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
    openapi.Info(
        title="Swagger Study API",
        default_version="v1",
        description="Swagger Studyλ₯Ό μœ„ν•œ API λ¬Έμ„œ",
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(name="test", email="dhkep03@gmail.com"),
        license=openapi.License(name="Test License"),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
)



from django.contrib import admin
from django.urls import path

from mytodoapp.views import TodosAPIView, TodoAPIView, DoneTodosAPIView, DoneTodoAPIView
from mytodoapp.views import CreateView
urlpatterns = [
    path('admin/', admin.site.urls),
    path('todo', TodosAPIView.as_view()),
    path('todo/<int:pk>',TodoAPIView.as_view()),
    path('done', DoneTodosAPIView.as_view()),
    path('done/<int:pk>',DoneTodoAPIView.as_view()),
    path('api/books/',CreateView.as_view()),

]

if settings.DEBUG:
    urlpatterns += [
        re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name="schema-json"),
        re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
        re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),    ]
  • μ‹€ν–‰
$ python manage.py runserver
  • 접속창에 localhost:8000/swagger 접속

profile
무럭무럭 자라볼까
post-custom-banner

0개의 λŒ“κΈ€