728x90
반응형
board_write.html
{% extends "base.html" %}
{% block contents %}
<section id="contact">
<div class="row contact-content">
<div class="col-seven tab-full animate-this input-box">
<h5>Enter the number of people entering</h5>
<form name="contactForm" method="POST" action="."> <!-- 현재 주소에 액션을 할 것이기에 .을 입력하거나 생략해도 됨-->
{% csrf_token %}
{% for field in form %}
<div class="form-field">
<!-- <label for="{{ field.id_for_label }}">{{ field.label }}</label> -->
{% ifequal field.name 'contents' %}
<textarea class="form-control" name="{{ field.name }}" placeholder="{{ field.label }}"></textarea>
{% else %}
<input type="{{ field.field.widget.input_type }}" class="form-control" id="{{ field.id_for_label }}" placeholder="{{ field.label }}" name="{{ field.name }}">
{% endifequal %}
</div>
{% if field.errors %}
<span style="color: red">{{ field.errors }}</span>
{% endif %}
{% endfor %}
<button type="submit" class="btn btn-primary">등록</button>
<button type="button" class="btn btn-primary" onclick="location.href='/board/list/'">돌아가기</button>
</form>
</div>
</div>
</section>
{% endblock %}
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('list/', views.board_list),
path('write/', views.board_write),
]
views.py
def board_write(request):
if request.method == 'POST':
form = BoardForm(request.POST)
if form.is_valid():
board = Board()
board.start_date = form.cleaned_data['start_date']
board.end_date = form.cleaned_data['end_date']
board.company = form.cleaned_data['company']
board.position = form.cleaned_data['position']
board.guest_name = form.cleaned_data['guest_name']
board.save()
return redirect('/board/list/')
else:
form = BoardForm()
return render(request, 'board_write.html', {'form': form})
반응형
'Project > access-control' 카테고리의 다른 글
Django 게시글 삭제 (0) | 2021.12.02 |
---|---|
Django 게시글 수정 (0) | 2021.12.01 |
상세 페이지 연결 (0) | 2021.11.29 |
Xlsxwriter 한글파일명 설정 및 행 높이 조절 (0) | 2021.11.26 |
Xlsxwriter 엑셀 export 기능 구현 (0) | 2021.11.25 |