728x90
반응형

board_detail.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 method="POST" action="{% url 'update' pk=board.id %}" enctype="multipart/form-data">
                {% csrf_token %}
                <div class="form-field">
                    <label for="start_date">시작일</label>
                    <input type="date" class="form-control" name="start_date" value="{{ board.start_date|date:'Y-m-d' }}" />
                    <label for="end_date">종료일</label>
                    <input type="date" class="form-control" name="end_date" value="{{ board.end_date|date:'Y-m-d' }}" />
                    <label for="company">업체명</label>
                    <input type="text" class="form-control" name="company" value="{{ board.company }}" />
                    <label for="position">직책</label>
                    <input type="text" class="form-control" name="position" value="{{ board.position }}" />
                    <label for="guest_name">이름</label>
                    <input type="text" class="form-control" name="guest_name" value="{{ board.guest_name }}" />
                </div>
                <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('detail/<int:pk>/update', views.update, name='update'),
    path('detail/<int:pk>/', views.board_detail, name='detail'),
    path('list/', views.board_list),
    path('write/', views.board_write),
]

 


views.py

def update(request, pk):
    board = Board.objects.get(pk=pk)
    if request.method == 'POST':
        form = BoardForm(request.POST, request.FILES)
        if form.is_valid():
            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/detail/'+str(pk))
    else:
        return redirect('/board/detail/'+str(pk))

 

반응형

'Project > access-control' 카테고리의 다른 글

PythonAnywhere 배포하기 (1) - Django 설정  (0) 2021.12.03
Django 게시글 삭제  (0) 2021.12.02
Django 게시글 등록  (0) 2021.11.30
상세 페이지 연결  (0) 2021.11.29
Xlsxwriter 한글파일명 설정 및 행 높이 조절  (0) 2021.11.26
복사했습니다!