Tags
- migrations
- Article & User
- Tree
- delete
- N:1
- 백트래킹
- 통계학
- 스택
- 큐
- regexp
- 뷰
- DB
- 그리디
- 완전검색
- SQL
- M:N
- outer join
- Vue
- distinct
- create
- update
- stack
- Django
- 쟝고
- 트리
- Queue
- ORM
- 이진트리
- count
- drf
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Notice
Recent Posts
Link
데이터 분석 기술 블로그
Django에 대하여(6)_form 활용 본문
사용자 입력 데이터를 받아 그대로 출력하는 서버를 만들어 볼게요.
먼저 사용자 입력 데이터를 받는 로직을 throw라고 하고 출력하는 서버를 catch라고 하겠습니다.
1. throw 로직 작성
#urls.py
urlpatterns = [
path('throw/', views.throw),
]
# views.py
def throw(request):
return render(request, 'articles/throw.html')
<-- articles/throw.html -->
{% extends 'articles/base.html' %}
{% block content %}
<h1>Throw</h1>
<form action="/catch/" method="GET">
<input type="text" id="message" name="message">
<input type="submit">
</form>
{% endblock content %}
2. catch 로직 작성
#urls.py
urlpatterns = [
path('catch/', views.catch),
]
# views.py
def catch(request):
message = request.GET.get('message')
context = {
'message': message,
}
return render(request, 'articles/catch.html', context)
<-- articles/throw.html -->
{% extends 'articles/base.html' %}
{% block content %}
<h1>Catch</h1>
<h3>{{ message }}를 받았습니다!</h3>
{% endblock content %}
3. HTTP request 객체
view 함수의 첫 번째 인자로, form으로 전송한 데이터뿐만 아니라 모든 요청 관련 데이터가 담겨 있습니다.
'백엔드' 카테고리의 다른 글
Django에 대하여(8)_App과 URL (0) | 2024.03.29 |
---|---|
Django에 대하여(7)_Django URLs (0) | 2024.03.28 |
Django에 대하여(5)_요청과 응답 (0) | 2024.03.26 |
Django에 대하여(4)_Django Template (0) | 2024.03.25 |
Django에 대하여(3)_프로젝트와 앱 (2) | 2024.03.24 |