本文整理汇总了Python中accounts.forms.LoginForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.save方法的具体用法?Python LoginForm.save怎么用?Python LoginForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoginView
# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import save [as 别名]
class LoginView(TemplateView):
template_name = "signin.html"
def __init__(self):
super(LoginView, self).__init__()
self.form = LoginForm()
def get_context(self, request, *args, **kwargs):
context = {
'form': self.form
}
return context
def get(self, request, *args, **kwargs):
return self.render_to_response(self.get_context(request))
def post(self, request, *args, **kwargs):
self.form = LoginForm(request.POST)
if self.form.is_valid():
self.form.save()
user = auth.authenticate(
email=self.form.user.email,
password=self.form.str_password
)
auth.login(request, user)
del request.POST['email']
del request.POST['password']
return redirect('index_page')
else:
return self.render_to_response(self.get_context(request))
示例2: login
# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import save [as 别名]
def login(request):
# get next parameter
next = request.REQUEST.get('next', settings.LOGIN_REDIRECT_URL)
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = form.save()
auth_login(request, user)
return redirect(next)
else:
form = LoginForm()
return render(request, 'accounts/login.html', {'form': form, 'next': next})
示例3: view_login
# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import save [as 别名]
def view_login(request):
next = request.GET.get('next', reverse('core_index'))
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return HttpResponseRedirect(next)
else:
form = LoginForm()
return render(
request,
'accounts/login.html',
{
'form': form,
'next': next
}
)