type
속성에 따라 동작 방식이 달라짐?key=value&key=value
형태로 전달throw & catch
throw
# first_project/urls.py
path('throw/', views.throw),
# articles/views.py
def throw(request):
return render(request, 'throw.html')
<!-- articles/templates/throw.html -->
<form action="/catch/" method="GET">
<label for="message">Throw</label>
<input type="text" id="message" name="message">
<input type="submit">
</form>
catch
# first_project/urls.py
path('catch/', views.catch),
# articles/views.py
def catch(request):
message = request.GET.get('message')
context = {
'message': message,
}
return render(request, 'catch.html', context)
<!-- articles/templates/catch.html -->
<h1>너가 던져서 내가 받은건 {{ message }}야!</h1>
<a href="/throw/">뒤로</a>
HttpRequest
객체를 만들고HttpRequest
를 뷰 함수의 첫 번째 인수로 전달. HttpResponse
개체를 반환한다.