집에서 해본거

kst5137·2022년 1월 24일
0
<form  method = "post" enctype="multipart/form-data" novalidate>
        {% csrf_token %}
<!--        {{videoForm}}-->
            제목 : {{videoForm.title}}

        <div>
           태그 : <select onchange="selectBoxChange({{ videoForm.tag }});">
                <option {{ videoForm.tag }} 음악 </option>
                <option {{ videoForm.tag }} 예능 </option>
                <option {{ videoForm.tag }} 자연 </option>
                <option {{ videoForm.tag }} 학습 </option>
            </select>
        </div>
        <div>
        썸네일 : {{ videoForm.file }}
        </div>
        <div>
        동영상파일 : {{ videoForm.file2 }}
        </div>




         <button type="submit" onclick="check">Upload</button>
<!--         버튼을 누르면 원래 action이라고 적힌 부분을 반복하지만 없기 때문에 현재 url로 보낸다.-->


    </form>
def update(request, bid) :
    post = Video.objects.get(Q(id=bid))  #게시글 하나를 가져오는것
    if request.method == "GET" :
        videoForm = VideoForm(instance=post)
        #특정 조건 id에 해당하는 값을 저장한다.
        return render(request,'Video/update.html',{'videoForm' : videoForm})
    elif request.method == "POST" :
        videoForm = VideoForm(request.POST, request.FILES)

        # boardForm에서 사용자가 보내온 데이터를 받느다
        if videoForm.is_valid():   #boardForm안에 값이 유효한다면
            post.title = videoForm.cleaned_data['title']
            post.tag = videoForm.cleaned_data['tag']
            # post.file = videoForm.cleaned_data['file']
            post.save()
            return redirect('/Video/list')

            # return render(request, 'Video/list.html',)
profile
공부중인 학생

0개의 댓글