old_contents: # from django.shortcuts import render
  # from django.views.generic import View
  # from django.views.generic import TemplateView
  # from django.http import HttpResponse
  #
  # '''
  # Date : 12 May, 2015
  # '''
  # # Create your views here.
  #
  #
  # #class Authentication(TemplateView):
  #
  # #    template_name = 'index.html'
  #     #def get(self, request, *args, **kwargs):
  
  from django.conf import settings
  from django.contrib.auth.forms import AuthenticationForm
  from django.contrib.auth import login, logout
  from django.contrib.auth.decorators import login_required
  from django.http import HttpResponseRedirect
  from django.utils.decorators import method_decorator
  from django.views.decorators.debug import sensitive_post_parameters
  from django.views.generic import FormView, View
  from .forms import PasswordForm
  
  class Login(FormView):
      form_class = AuthenticationForm
      template_name = 'index.html'
      success_url = '/dashboard'
  
      def form_valid(self, form):
          #redirect_to = settings.LOGIN_REDIRECT_URL
          #print('before :D ')
          login(self.request, form.get_user())
          #print('after :/ ')
          #if self.request.session.test_cookie_worked():
          #    self.request.session.delete_test_cookie()
          #return HttpResponseRedirect(redirect_to)
          return super(Login, self).form_valid(form)
  
      def form_invalid(self, form):
          print('invalid')
          return self.render_to_response(self.get_context_data(form=form))
  
      #@method_decorator(sensitive_post_parameters('password'))
      #def dispatch(self, request, *args, **kwargs):
      #    #request.session.set_test_cookie()
      #    return super(Login, self).dispatch(request, *args, **kwargs)
  
  class Logout(View):
      def get(self, request, *args, **kwargs):
          logout(request)
          return HttpResponseRedirect(settings.LOGOUT_REDIRECT_URL)
  
  #@login_required()
  class AddData(FormView):
      """
        Add new data
      """
      form_class = PasswordForm
      success_url = '/dashboard'
      template_name = 'forms/add.html'
  
      def form_valid(self, form):
          print(self.request.POST)
          return super(AddData, self).form_valid(form)
  
      def form_invalid(self, form):
          print('invalid')
new_contents: # from django.shortcuts import render
  # from django.views.generic import View
  # from django.views.generic import TemplateView
  # from django.http import HttpResponse
  #
  # '''
  # Date : 12 May, 2015
  # '''
  # # Create your views here.
  #
  #
  # #class Authentication(TemplateView):
  #
  # #    template_name = 'index.html'
  #     #def get(self, request, *args, **kwargs):
  
  from django.conf import settings
  from django.contrib.auth.forms import AuthenticationForm
  from django.contrib.auth import login, logout
  from django.contrib.auth.decorators import login_required
  from django.http import HttpResponseRedirect
  from django.utils.decorators import method_decorator
  from django.views.decorators.debug import sensitive_post_parameters
  from django.views.generic import FormView, View
  from .models import Password
  from django.views.generic.edit import CreateView
  from django.utils import timezone
  from .crypto import Secret
  
  
  class Login(FormView):
      form_class = AuthenticationForm
      template_name = 'index.html'
      success_url = '/dashboard'
  
      def form_valid(self, form):
          login(self.request, form.get_user())
          return super(Login, self).form_valid(form)
  
      def form_invalid(self, form):
          print('invalid')
          return self.render_to_response(self.get_context_data(form=form))
  
  
  class Logout(View):
      def get(self, request, *args, **kwargs):
          logout(request)
          return HttpResponseRedirect(settings.LOGOUT_REDIRECT_URL)
  
  class LoggedInMixin(object):
  
      @method_decorator(login_required)
      def dispatch(self, *args, **kwargs):
          return super(LoggedInMixin, self).dispatch(*args, **kwargs)
  
  class AddData(LoggedInMixin, CreateView):
      """
        Add new data
      """
      model = Password
      success_url = '/dashboard'
      template_name = 'forms/add.html'
      fields = ['site_url', 'username', 'email', 'password', 'note']
  
      def form_valid(self, form):
          Hiren = Secret(self.request.POST.get('key'))
          form.instance.password = Hiren.encrypt(self.request.POST.get('password'))
          form.instance.note = Hiren.encrypt(self.request.POST.get('note'))
          form.instance.added_at = timezone.now()
          return super(AddData, self).form_valid(form)
  
      def form_invalid(self, form):
          return self.render_to_response(self.get_context_data(form=form))
subject: create a view for form