Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- boj
- SQL
- 알고리즘
- CSV
- 코딩테스트
- django
- Trie
- Algorithm
- 시뮬레이션
- 모의SW역량테스트
- Priority Queue
- spring boot
- hash table
- Vue.js
- gpdb
- 알고리듬
- programmers
- SWEA
- JavaScript
- BFS
- Data Structure
- aws
- DFS
- Back tracking
- 코테
- Linked list
- Bruth Force
- Python
- 구현
- GitHub
Archives
- Today
- Total
hotamul의 개발 이야기
[Django] drf_spectacular 사용해보기 본문
django, djangorestframework
를 사용하여 api 서버를 만들어보기로 했다.
그리고 [Django] User Model 커스터마이징 #6 (TDD) 까지 진행해보면서 자동으로 api 문서를 작성할 수 있는 drf_spectacular
에 대해 알게 되어 적용 해보려고 한다.
pip package 추가
나는 requirements.txt
로 패키지 관리를 하고 있어서 requirements.txt
에 drf-spectacular
패키지를 추가해 주었다.
...
drf-spectacular>=0.15.1,<0.16
app, url 추가
이제 localhost:8000/api/docs
url로 api 문서를 보기 위해 먼저 django 프로젝트 최상위 app/settings.py
에 app을 추가한다.
# app/settings.py
...
INSTALLED_APPS = [
...
'rest_framework',
'drf_spectacular',
]
다음 app/urls.py
에 아래와 같이 주소를 추가한다. api/schema
는 schema를 다운로드 할 수 있는 url이다.
# app/urls.py
...
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularSwaggerView,
)
...
urlpatterns = [
...
path('api/schema/', SpectacularAPIView.as_view(), name='api-schema'),
path(
'api/docs/',
SpectacularSwaggerView.as_view(url_name='api-schema'),
name='api-docs',
),
...
]
확인해보면 짜잔!
'Dev. > Django' 카테고리의 다른 글
[Django] APIView vs Viewsets (0) | 2022.07.23 |
---|---|
[Django] User Model 커스터마이징 #6 (TDD) (0) | 2022.07.13 |
[Django] User Model 커스터마이징 #5 (TDD) (0) | 2022.07.06 |
[Django] User Model 커스터마이징 #4 (TDD) (0) | 2022.07.03 |
[Django] User Model 커스터마이징 #3 (TDD) (0) | 2022.07.01 |
Comments