Django class based view를 이용하여 동일한 페이지에 GET 과 POST를 모두 표시하는 방법.
1. View 작성(app/views.py)
class GetPostView(View): template_name = 'getpost.html' data = [ {'name': 'fox', 'title': 'test1', 'is_published': True }, {'name': 'wolf', 'title': 'test 2', 'is_published': False}, {'name': 'cat', 'title': 'life of cat', 'is_published': True}, ] def get(self, request, *argc, **kwargs): context = { 'data': self.data, } return render(request, self.template_name, context) def post(self, request, *argc, **kwargs): result = request.POST context = { 'data': self.data, 'result': result, } return render(request, self.template_name, context)