1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| from django.shortcuts import render , HttpResponse from .forms import MessageBoardForm from django.views.decorators.http import require_http_methods
@require_http_methods(['GET','POST']) def index(request): if request.method == 'GET': f = MessageBoardForm() context = { 'form':f } return render(request, 'index.html' , context=context) elif request.method == 'POST': f = MessageBoardForm(request.POST) if f.is_valid(): title = f.cleaned_data['title'] content = f.cleaned_data['content'] email = f.cleaned_data['email'] return HttpResponse(f"{title} , {content} , {email}") else: return HttpResponse(f.errors)
|