from django.shortcuts import render, get_object_or_404, redirect
from .models import Page
from .forms import PageForm

RECENT = 10

def index(request):
    recently_updated = Page.objects.order_by('-updated_at').all()[:RECENT]
    return render(request, 'mainstay_wiki/index.html', {'recently_updated': recently_updated})


def page(request, title):
    print(title)
    page_ = get_object_or_404(Page, title=title)
    context = {'page': page_}
    return render(request, 'mainstay_wiki/page.html', context)


def add_page(request):
    
    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('mainstay_wiki:index')
        else:
            print('errors!')
    else:
        form = PageForm()

    return render(request, 'mainstay_wiki/add.html', {'form': form})


def edit_page(request, title):
    page_ = get_object_or_404(Page, title=title)
    if request.method == 'POST':
        form = PageForm(request.POST, instance=page_)
        if form.is_valid():
            form.save()
            return redirect('mainstay_wiki:page', page_.title)
        else:
            print('errors!')
    else:
        form = PageForm(instance=page_)

    return render(request, 'mainstay_wiki/edit.html', {'form': form})

@@ -58,16 +58,53 @@
 edirect%0A
+from django.contrib import messages%0A%0A
 from .mo
@@ -120,16 +120,16 @@
 rt Page%0A
-
 from .fo
@@ -149,16 +149,17 @@
 geForm%0A%0A
+%0A
 RECENT =
@@ -385,25 +385,8 @@
 e):%0A
-    print(title)%0A
     
@@ -552,13 +552,8 @@
 t):%0A
-    %0A
     
@@ -663,32 +663,84 @@
     form.save()%0A
+            messages.success(request, 'Page added')%0A
             retu
@@ -796,38 +796,55 @@
             
-print('e
+messages.error(request, 'E
 rrors
-!
 ')%0A    else:
@@ -1153,32 +1153,86 @@
     form.save()%0A
+            messages.success(request, 'Page editted')%0A
             retu
@@ -1308,22 +1308,39 @@
     
-print('e
+messages.error(request, 'E
 rrors
-!
 ')%0A 

Add message output