我知道我可以使用 request.user.is_authenticated() 检查用户是否已登录,并且我想为基于类的视图使用装饰器,例如函数视图的装饰器:login_required,我该怎么办?
我想要这样的东西:
class AddCompanyInfoHandler(View):
model = Company
@check_login_decorator
def get(self, request):
form = EnrollCompanyForm()
return render(request, 'student/company_form.html', {'form': form,})
@check_login_decorator
def post(self, request):
form = EnrollCompanyForm(request.POST)
if form.is_valid():
form_data = form.cleaned_data
current_user = request.user
company = Company.objects.create_company(current_user, form_data)
company.save()
return HttpResponse("Create Company USer Successfully!")
else:
return render(request, 'student/company_form.html', {'form': form,})