예제 #1
0
def create(request):
    new_diary = Diary()
    new_diary.title = request.POST['title']
    new_diary.author = request.POST['author']
    new_diary.image = request.FILES['image']
    new_diary.body = request.POST['body']
    new_diary.pub_date = timezone.now()
    new_diary.save()
    return redirect('home')
예제 #2
0
def create(request):
    # 글을 작성할 경우 POST 방식
    if request.method == "POST":
        new_diary = Diary()
        new_diary.title = request.POST['title']
        new_diary.pub_date = timezone.datetime.now()
        new_diary.mood = request.POST['mood']
        new_diary.weather = request.POST['weather']
        new_diary.body = request.POST['body']
        new_diary.image = request.FILES['image']

        # db에 생성된 diary 객체 저장
        new_diary.save()
        return redirect('home')

    # 단순 create 페이지로 이동할 경우 GET 방식으로 들어감
    else:
        return render(request, 'new.html')