当前位置: 首页>>代码示例>>Python>>正文


Python context_processors.csrf方法代码示例

本文整理汇总了Python中django.template.context_processors.csrf方法的典型用法代码示例。如果您正苦于以下问题:Python context_processors.csrf方法的具体用法?Python context_processors.csrf怎么用?Python context_processors.csrf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.context_processors的用法示例。


在下文中一共展示了context_processors.csrf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: thread_create

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def thread_create(request, fid=None):
    forum = get_object_or_404(Forum, id=fid)
    data = wrap_data_forum(request)
    user = data['user']
    data.update(csrf(request)) 
    data['forum'] = forum
    success = False
    if request.method == 'POST':
        thread_creation_form = ThreadCreationForm(request.POST)
        if thread_creation_form.is_valid():
            thread = thread_creation_form.save(author=user, forum=forum)
            success = True
        else:
            for error in thread_creation_form.non_field_errors():
                data['errors'].append(error)
    else:
        thread_creation_form = ThreadCreationForm(None)
    if success:
        response = redirect(reverse('forum_thread', args=(thread.id,)))
    else:
        data['forms'].append(thread_creation_form)
        data['thread_creation_form'] = thread_creation_form
        response = _r('forum/thread_create.html', data)
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:26,代码来源:views.py

示例2: message_create

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def message_create(request, tid=None):
    thread = get_object_or_404(ForumThread, id=tid)
    data = wrap_data_forum(request)
    data['thread'] = thread
    user = data['user']
    data.update(csrf(request)) 
    success = False
    if request.method == 'POST':
        message_creation_form = MessageCreationForm(request.POST)
        if message_creation_form.is_valid():
            message = message_creation_form.save(author=user, thread=thread)
            success = True
        else:
            for error in auth_form.non_field_errors():
                data['errors'].append(error)
    else:
        message_creation_form = MessageCreationForm(None)
    if success:
        response = redirect(reverse('forum_thread', args=(thread.id,)))
    else:
        data['message_creation_form'] = message_creation_form
        response = _r('forum/message_create.html', data)

    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:26,代码来源:views.py

示例3: prelaunch

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def prelaunch(request):
    if is_prelaunch_mode():
        data = get_view_context(request)
        data.update(csrf(request))

        success = False
        if request.method == 'POST':
            prelaunch_signup_form = PrelaunchSignupForm(request.POST)
            if prelaunch_signup_form.is_valid():
                site = get_current_site(request)
                prelaunch_signup = prelaunch_signup_form.save(site)
                success = True
            else:
                for error in prelaunch_signup_form.non_field_errors():
                    data['errors'].append(error)
        else:
            prelaunch_signup_form = PrelaunchSignupForm()
        data['prelaunch_signup_form'] = prelaunch_signup_form
        data['success'] = success
        prelaunch_template = htk_setting('HTK_PRELAUNCH_TEMPLATE', HTK_PRELAUNCH_TEMPLATE)
        response = _r(prelaunch_template, data)
    else:
        response = redirect(htk_setting('HTK_INDEX_URL_NAME'))
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:26,代码来源:views.py

示例4: register_user

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def register_user(request):
    '''Registers user.
       Renders success page on success,
               register page on failure.'''

    # User is submitting form.
    # Read from form and save
    # form data as new user.
    if request.method == "POST":
        form = MyRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/register_success')
    args = {}
    args.update(csrf(request))
    args['form'] = MyRegistrationForm(request.POST)
    print args
    return render_to_response('register.html', args) 
开发者ID:clayball,项目名称:nector,代码行数:20,代码来源:views.py

示例5: edit_business_unit

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def edit_business_unit(request, bu_id):
    business_unit = get_object_or_404(BusinessUnit, pk=int(bu_id))
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        if request.user.is_staff:
            form = EditUserBusinessUnitForm(request.POST, instance=business_unit)
        else:
            form = EditBusinessUnitForm(request.POST, instance=business_unit)
        if form.is_valid():
            new_business_unit = form.save(commit=False)
            new_business_unit.save()
            form.save_m2m()
            return redirect('bu_dashboard', new_business_unit.id)
    else:
        if request.user.is_staff:
            form = EditUserBusinessUnitForm(instance=business_unit)
        else:
            form = EditBusinessUnitForm(instance=business_unit)
    c = {'form': form, 'business_unit': business_unit}
    return render(request, 'forms/edit_business_unit.html', c) 
开发者ID:salopensource,项目名称:sal,代码行数:23,代码来源:views.py

示例6: new_user

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def new_user(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        form = forms.NewUserForm(request.POST)
        if form.is_valid():
            user = form.save()
            user_profile = UserProfile.objects.get(user=user)
            user_profile.level = request.POST['user_level']
            user_profile.save()
            return redirect('manage_users')
    else:
        form = forms.NewUserForm()
    c = {'form': form}

    return render(request, 'forms/new_user.html', c) 
开发者ID:salopensource,项目名称:sal,代码行数:18,代码来源:settings_views.py

示例7: _create_context

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def _create_context(self, request):
        raw_filters = request.session.get(self.filters_key, {})
        filters = [BaseFilter.from_dict(filter_d) for _, filter_d in raw_filters.items()]
        avg_overall_time = self._avg_num_queries(filters)
        c = {
            'request': request,
            'num_requests': models.Request.objects.filter(*filters).count(),
            'num_profiles': models.Profile.objects.filter(*filters).count(),
            'avg_num_queries': avg_overall_time,
            'avg_time_spent_on_queries': self._avg_time_spent_on_queries(filters),
            'avg_overall_time': self._avg_overall_time(filters),
            'longest_queries_by_view': self._longest_query_by_view(filters),
            'most_time_spent_in_db': self._time_spent_in_db_by_view(filters),
            'most_queries': self._num_queries_by_view(filters),
            'filters': raw_filters
        }
        c.update(csrf(request))
        return c 
开发者ID:jazzband,项目名称:django-silk,代码行数:20,代码来源:summary.py

示例8: widget

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def widget(self):
        context = {'widget_id': self.id, 'widget_title': self.title, 'widget_icon': self.widget_icon,
                   'widget_type': self.widget_type, 'form': self, 'widget': self}
        context.update(csrf(self.request))
        self.context(context)
        return loader.render_to_string(self.template, context) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:8,代码来源:dashboard.py

示例9: search_view

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def search_view(request):
    context = {}
    if request.POST:
        context.update(csrf(request))
        context['request'] = request.POST['package']
        context['package_list'] = Package.objects.filter(c_name__icontains=request.POST['package'])[:24]
    else:
        return HttpResponseBadRequest()
    return render(request, 'search.html', context) 
开发者ID:82Flex,项目名称:DCRM,代码行数:11,代码来源:search.py

示例10: home

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def home(request, template_name="suponoff/index.html"):
    context = get_index_template_data()
    context.update(csrf(request))
    resp = render_to_response(template_name, context)
    return resp 
开发者ID:GambitResearch,项目名称:suponoff,代码行数:7,代码来源:views.py

示例11: register_social_login

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def register_social_login(
    request,
    data=None,
    resend_confirmation_url_name='account_resend_confirmation',
    template='account/register_social_login.html',
    renderer=_r
):
    """For when a user is already associated with this email and has a usable password set
    """
    from htk.apps.accounts.forms.auth import SocialRegistrationAuthenticationForm

    if data is None:
        data = wrap_data(request)

    email = request.session.get(SOCIAL_REGISTRATION_SETTING_EMAIL)
    data['email'] = email
    data.update(csrf(request))

    success = False
    if request.method == 'POST':
        auth_form = SocialRegistrationAuthenticationForm(email, request.POST)
        if auth_form.is_valid():
            user = auth_form.get_user()
            login_authenticated_user(request, user)
            success = True
        else:
            for error in auth_form.non_field_errors():
                data['errors'].append(error)
            auth_user = auth_form.get_user()
            if auth_user and not auth_user.is_active:
                msg = get_resend_confirmation_help_message(resend_confirmation_url_name, email=auth_user.email)
                data['errors'].append(msg)
    else:
        auth_form = SocialRegistrationAuthenticationForm(email)

    if success:
        response = redirect_to_social_auth_complete(request)
    else:
        data['auth_form'] = auth_form
        response = renderer(request, template, data=data)
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:43,代码来源:views.py

示例12: forgot_password

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def forgot_password(
    request,
    data=None,
    redirect_url_name='account_password_reset_done',
    template='account/forgot_password.html',
    email_template=None,
    email_subject=None,
    email_sender=None,
    renderer=_r
):
    """Modeled after django.contrib.auth.views.password_reset
    """
    from htk.apps.accounts.forms.auth import PasswordResetFormHtmlEmail

    if data is None:
        wrap_data(request)

    data.update(csrf(request))
    if request.method == 'POST':
        form = PasswordResetFormHtmlEmail(request.POST)
        if form.is_valid():
            opts = {
                'request': request,
            }
            form.save(email_template=email_template, email_subject=email_subject, email_sender=email_sender, **opts)
            response = redirect(redirect_url_name)
        else:
            for error in form.non_field_errors():
                data['errors'].append(error)
            data['form'] = form
            response = renderer(request, template, data=data)
    else:
        form = PasswordResetFormHtmlEmail()
        data['form'] = form
        response = renderer(request, template, data=data)
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:38,代码来源:views.py

示例13: forum

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def forum(request, fid):
    data = wrap_data_forum(request)
    forum = get_object_or_404(Forum, id=fid)
    data.update(csrf(request)) 
    data['forum'] = forum
    thread_creation_form = ThreadCreationForm()
    data['thread_creation_form'] = thread_creation_form
    data['threads'] = forum.threads.order_by('sticky', '-updated')
    response = _r('forum/forum.html', data)
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:12,代码来源:views.py

示例14: login

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def login(request):
    '''Renders login page.'''
    c = {}

    if request.user.is_authenticated():
        return loggedin(request)

    if 'next' in request.GET:
        c['next'] = request.GET['next']

    c.update(csrf(request))
    return render_to_response('login.html', c) 
开发者ID:clayball,项目名称:nector,代码行数:14,代码来源:views.py

示例15: edit_scan

# 需要导入模块: from django.template import context_processors [as 别名]
# 或者: from django.template.context_processors import csrf [as 别名]
def edit_scan(request):

    context = {}

    scan_name = request.POST.get("selected_scan_name")

    scan_obj = get_object_or_404(ScanType, scan_name=scan_name, user=request.user)

    scan_options = []

    dirty_scan_options = scan_obj.scan_options

    if dirty_scan_options:
        if 'version_detection' in dirty_scan_options:
            scan_options.append('version_detection')
        if 'os_and_services' in dirty_scan_options:
            scan_options.append('os_and_services')
        if 'fast' in dirty_scan_options:
            scan_options.append('fast')
        if 'no_ping' in dirty_scan_options:
            scan_options.append('no_ping')

    scan_obj.scan_options = scan_options

    form = ScansForm(instance=scan_obj)

    if request.user.is_authenticated():
        saved_scans = ScanType.objects.filter(user=request.user)
        context['saved_scans'] = saved_scans

    context.update(csrf(request))
    context['form'] = form
    return render(request, 'scans/scans.html', context) 
开发者ID:clayball,项目名称:nector,代码行数:35,代码来源:views.py


注:本文中的django.template.context_processors.csrf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。