POST /login HTTP/1.1
Host: example.com
Content-Type: application/json
Authorization: Bearer abc123
User-Agent: Mozilla/5.0
Content-Length: 49
{
"username": "john_doe",
"password": "1234"
}
Start Line: POST /login HTTP/1.1
Headers:
Content-Type: JSON 형식
Authorization: 토큰 포함
User-Agent: 브라우저 정보
Boy:
JSON 형태의 로그인 정보
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 85
Set-Cookie: sessionid=abc123; HttpOnly; Path=/
{
"message": "Login successful",
"user_id": 42,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
✅ request.GET
예시:
# URL: /search?query=apple
query = request.GET.get('query') # 'apple'
✅ request.data
예시:
POST 요청 body: { "username": "john", "password": "1234" }
username = request.data.get('username')
✅ 예시 코드로 요약
def my_view(request):
method = request.method # GET, POST 등
path = request.path # /articles/1/
query = request.GET.get('q') # 쿼리 파라미터
body = request.body # raw body (bytes)
host = request.get_host() # example.com
full_url = request.build_absolute_uri()
is_https = request.is_secure()
user = request.user # 인증된 사용자 객체
headers = request.headers # 헤더 dict