Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginView(View):
- def get(self, request, *args, **kwargs):
- # create a new form instance
- form = forms.LoginForm()
- return render(request, "login.html", {'form': form})
- def post(self, request, *args, **kwargs):
- # create a form instance and populate it with data from the request
- form = forms.LoginForm(request.POST)
- # check whether is valid
- if form.is_valid():
- form.save()
- user_name = form.cleaned_data['username']
- password = form.cleaned_data['password']
- user = authenticate(username=user_name, password=password)
- if user is not None:
- login(request, user)
- return HttpResponseRedirect('/boletim/')
- else:
- return HttpResponseRedirect('/login/')
- else:
- return HttpResponseRedirect('/login/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement