http -a admin:password123 POST http://127.0.0.1:8000/snippets/ code="print(789)" { "id": 1, "owner": "admin", "title": "foo", "code": "print(789)", "linenos": false, "language": "python", "style": "friendly" } Snippet 모델 추가 작성 모델에 내용 추가 models.py의 Snippet 모델에 작성 User와 연결할 uwner ForeignKey와 하이라이트 추가 owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE) highligh..
전체 글
코드만 봐도 다 알 수 있다.Class-based Views Class-based Views란? APIView 클래스를 사용해 구현한 뷰 문법이 훨씬 간단하고 명료 해짐 mixin을 사용하면 crud 함수까지 자동으로 상속받아 구현하지 않아도 됨 Class-based Views 작성 from snippets.models import Snippet from snippets.serializers import SnippetSerializer from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status class SnippetLis..
항목 주소 공지사항 알림 상품 카테고리 후기 광고 채팅 파일 신고 유저 로그 직접 제작한 ERD로써 저작권은 나에게 있으므로 복붙해서 써도 상관 없다. 지속적으로 작성 중에 있어서 수정될 수 있고 항상 정상 작동 할 지는 불분명하다. 회원이 중심이 되도록 만들어서 그런지 스노우 플레이크의 형태를 띈다. 그런데 이러면 수평적 확장이 힘들어 보일 수 있는데 스노우 플레이크 형태이므로 수평적으로 확장될 필요는 없다. 각 서비스의 경계를 명확하게 표기 해주기만 하면 문제 없이 모든 방향으로 확장해 나갈 수 있다. 화질이 깨지므로 자세하게 보고 싶다면 아래 erdcloud의 링크를 참고 https://www.erdcloud.com/d/98H5gmB6imWXe4ecc 중고거래_khw 회원을 가장 왼쪽에 두고 각 구..
Request, Response 객체, Status 모듈 Request 객체 REST framework의 Request 객체는 HttpRequest 객체를 상속 받고 있음 더 유연한 request 파싱을 제공 코어 기능은 request.data임 request.post는 오직 POST에서만 있음 request.POST # Only handles form data. Only works for 'POST' method. request.data # Handles arbitrary data. Works for 'POST', 'PUT' and 'PATCH' methods. Response 객체 클라이언트에게 요청 받은 타입으로 리턴함 return Response(data) # Renders to content t..
환경 설정 pygments 설치 snippets 앱 만들기 pip install pygments # We'll be using this for the code highlighting cd tutorial python manage.py startapp snippets settings.py의 INSTALLED_APPS에 snippets 추가 INSTALLED_APPS = [ ... 'rest_framework', 'snippets', ] Serializer 작성 모델 적용 모델 작성 Snippet 모델 작성 from django.db import models from pygments.lexers import get_all_lexers from pygments.styles import get_all_style..