ビュー.py
def login_user(request):
if request.POST:
sform = LoginForm(request.POST)
rform = UserForm()
if sform.is_valid():
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username = username,password = password)
if user is not None:
if user.is_active:
login(request,user)
return redirect(request.path)
else:
state = "Your account is not active."
#or first set the user to is active and then log in
return redirect('acitvate_account',user = user)
return render_to_response('home.html',{'state':state,'user':user},context_instance = RequestContext(request))
else:
state = "Incorrect Username or Password"
#sform = LoginForm()
form = LoginForm()
return render_to_response('register.html',{'state':state,'sform':sform,'rform':rform,'form':form},context_instance = RequestContext(request))
else:
state = "Invalid form"
dLoginForm = LoginForm()
rform = PartialSignupForm()
return render_to_response('register.html',{'sform':sform,'rform':rform,'form':form},context_instance = RequestContext(request))
else:
dLoginForm = LoginForm()
rform = PartialSignupForm()
return render_to_response('category.html',{'dLoginForm':dLoginForm,'rform':rform},context_instance = RequestContext(request))
urls.py
urlpatterns += patterns('beenthere.views',
#beenthere urls
(r'^$','index'),
(r'^home2/$','category'),
(r'^accounts/login/$','login_user'),
(r'^accounts/register/$','register_user'),
(r'^home/(?P<user>\w*)$','home'),
(r'^logout/','logout_user'),
)
疑問に思う
リクエストの送信元と同じ URL をリダイレクトするにはどうすればよいでしょうか。request.path を使用してみましたが、/accounts/login/ url にリダイレクトされてしまいます。