本文整理汇总了Python中django.contrib.auth.mixins.LoginRequiredMixin方法的典型用法代码示例。如果您正苦于以下问题:Python mixins.LoginRequiredMixin方法的具体用法?Python mixins.LoginRequiredMixin怎么用?Python mixins.LoginRequiredMixin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.mixins
的用法示例。
在下文中一共展示了mixins.LoginRequiredMixin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch
# 需要导入模块: from django.contrib.auth import mixins [as 别名]
# 或者: from django.contrib.auth.mixins import LoginRequiredMixin [as 别名]
def dispatch(self, request, *args, **kwargs):
try:
# Check that the logged-in user has a Comrade instance too:
# even just trying to access the field will fail if not.
request.user.comrade
except Comrade.DoesNotExist:
# If not, redirect to create one and remember to come back
# here afterward.
return HttpResponseRedirect(
'{account_url}?{query_string}'.format(
account_url=reverse('account'),
query_string=urlencode({'next': request.path})))
return super(ComradeRequiredMixin, self).dispatch(request, *args, **kwargs)
# If the logged-in user doesn't have an ApplicantApproval object,
# redirect them to create one.
# If the logged-in user has an ApplicantApproval object that isn't approved,
# redirect them to the eligibility results page.
#
# This mixin requires a 'round_slug' view keyword argument.
#
# Note that LoginRequiredMixin must be to the left of this class in the
# view's list of parent classes, and the base View must be to the right.
示例2: post
# 需要导入模块: from django.contrib.auth import mixins [as 别名]
# 或者: from django.contrib.auth.mixins import LoginRequiredMixin [as 别名]
def post(self, request, section, pk):
form = MessageForm(request.POST)
if form.is_valid():
form = form.save(commit=False)
form.user = request.user
form.topic_id = pk
form.save()
return redirect("/forum/section/{}/{}/?page=last".format(section, pk))
# class MessageCreate(LoginRequiredMixin, CreateView):
# """Создание темы на форуме"""
# model = Message
# form_class = MessageForm
# template_name = 'forum/topic-detail.html'
#
# def form_valid(self, form):
# form.instance.user = self.request.user
# form.instance.topic_id = self.kwargs.get("pk")
# form.save()
# return super().form_valid(form)
示例3: get_context_data
# 需要导入模块: from django.contrib.auth import mixins [as 别名]
# 或者: from django.contrib.auth.mixins import LoginRequiredMixin [as 别名]
def get_context_data(self, **kwargs):
"""
Add User Information to Manual Menu page.
:param kwargs:
:return:
"""
# get information from the database
context = super().get_context_data(**kwargs)
# get the current user and related profile
current_user = self.request.user
profile = current_user.profile
# load up the context for the template
context['current_user'] = current_user
context['user_profile'] = profile
return context
# class ManualNotification(LoginRequiredMixin, TemplateView):
# """
# Ask a question or notify the user of something.
# """
# template_name = 'fpiweb/manual_generic_notification.html'
#
# def get_context_data(self, **kwargs):
# """
# Get info from reqest and populate context from it.
#
# :param kwargs:
# :return:
# """
# context = super(ManualNotification, self.get_context_data(**kwargs))
# request = context.get_request()
# title = request.