def signup(request): if request.method == "POST": user = User() form = LoginForm(request.POST, instance=user) user = form.save(commit=False) user.save() return redirect('/') return render_to_response('signup.html', context_instance=RequestContext(request))
def login(request): data = None if request.method == "POST": try: form = LoginForm(request.POST) if form.is_valid(): # DBチェック user = User.objects.get(username=request.POST["username"], password=request.POST["password"]) # レコードがあったらセッションにユーザ情報書き込む request.session['login_session'] = user.id return redirect('/') data = {'form': form} except ObjectDoesNotExist: messages.add_message(request, messages.ERROR, 'ユーザ名かパスワードが間違っています。') return HttpResponseRedirect('/login') return render(request, 'login.html', data)