本文整理汇总了Python中django.core.context_processors.csrf方法的典型用法代码示例。如果您正苦于以下问题:Python context_processors.csrf方法的具体用法?Python context_processors.csrf怎么用?Python context_processors.csrf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.context_processors
的用法示例。
在下文中一共展示了context_processors.csrf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prototype_view
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def prototype_view(request, name):
proto = Prototype.objects.get(pk=name)
n_stable = 0
for entry in proto.entry_set.all():
if entry.stable:
n_stable += 1
data = get_globals()
data['prototype'] = proto
data['n_stable'] = n_stable
if request.method == 'POST':
data['primitive'] = request.POST.get('primitive')
structure = proto.structure
if not structure:
example = proto.entry_set.all()
if example.exists():
structure = example[0].structure
data['structure'] = structure
data.update(csrf(request))
return render_to_response('materials/prototype.html',
data,
RequestContext(request))
示例2: get
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def get(self, request, *args, **kwargs):
value = request.GET.get('q', '')
cityquery = int(request.GET.get('city', '25'))
# get the deal results:
deals = Deal.objects.filter(title__icontains=value)\
.filter(location__icontains=cityquery)
# get the rendered list of deals
rendered_deal_list = self.render_deal_list(
request,
queryset=deals,
title='Search Results',
zero_items_message='Your search - {} - in {} \
did not match any deals.'
.format(value, ALL_LOCATIONS[cityquery - 1][1]),
description='{} deal(s) found for this search.'.format(len(deals))
)
context = {
'rendered_deal_list': rendered_deal_list
}
context.update(csrf(request))
return TemplateResponse(request, 'deals/searchresult.html', context)
示例3: user_profile
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def user_profile(request):
if request.method == 'POST':
# populate form with original instance and add post info on top of that
uform = UserForm(request.POST, instance=request.user)
pform = UserProfileForm(request.POST, instance=request.user.profile)
if uform.is_valid() and pform.is_valid():
uform.save()
pform.save()
messages.success(request, 'Profile details updated')
else:
user = request.user
uform = UserForm(instance=user)
profile = user.profile
pform = UserProfileForm(instance=profile)
context = {}
context.update(csrf(request))
context['uform'] = uform
context['pform'] = pform
return render_to_response(
'pages/profile.html',
context,
context_instance=RequestContext(request))
示例4: entry_view
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def entry_view(request, entry_id):
entry = Entry.objects.get(pk=entry_id)
data = {'entry': entry}
if entry.calculation_set.filter(label='static').count() != 0:
data['entry_structure'] = entry.calculation_set.filter(label='static')[0].output
elif entry.calculation_set.filter(label='standard').count() != 0:
data['entry_structure'] = entry.calculation_set.filter(label='standard')[0].output
else:
data['entry_structure'] = entry.input
data = get_globals(data)
if request.method == 'POST':
p = request.POST
data['primitive'] = bool(int(p.get('primitive', '0')))
if p.get('calculate'):
t = Task.create(entry, 'static')
t.save()
if p.get('add_keyword'):
kw = MetaData.get('Keyword', p['add_keyword'])
kw.entry_set.add(entry)
if p.get('add_hold'):
hold = MetaData.get('Hold', p['add_hold'])
hold.entry_set.add(entry)
#pdf = get_pdf(entry.input)
#data['pdf'] = pdf.get_flot_script()
data.update(csrf(request))
return render_to_response('materials/entry.html',
data,
RequestContext(request))
示例5: job_view
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def job_view(request, job_id):
job = Job.objects.get(id=job_id)
in_dir, stdout = ('', '')
if job.state == 1:
in_dir = job.account.execute('ls %s' % (job.run_path))
stdout = job.account.execute('cat %s/stdout.txt' % (job.run_path))
data = {'job': job,
'files': in_dir,
'stdout': stdout}
if request.method == 'POST':
job.collect()
data.update(csrf(request))
return render_to_response('computing/job.html',
data,
RequestContext(request))
示例6: queue_view
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def queue_view(request):
upcoming = {}
running = Job.objects.filter(state=1).order_by('-created')
recent_ = Calculation.objects.filter(label='static',converged=True).order_by('-id')[:25]
recent_name_dict = dict([(str(c.entry.id), format_html(c.comp)) for c in recent_])
recent_finished_dict = dict([(str(c.entry.id), c.entry.task_set.order_by('-finished')[0].finished) for c in recent_])
recent_project_dict = dict([(str(c.entry.id),
', '.join(p.name for p in c.entry.task_set.order_by('-finished')[0].projects))
for c in recent_])
recent_ids = list(map(lambda x: x[0], sorted(recent_finished_dict.items(), key=lambda x: x[1],
reverse=True)))
count = running.count()
data = {'running':running[:20],
'count':count,
'recent_name_dict': recent_name_dict,
'recent_finished_dict': recent_finished_dict,
'recent_project_dict': recent_project_dict,
'recent_ids':recent_ids,
}
data.update(csrf(request))
return render_to_response('computing/queue.html',
data,
RequestContext(request))
示例7: external_task_tutorial
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def external_task_tutorial(request, context):
""" Handle tutorials. On a GET, decide whether to serve up a tutorial.
On a POST, record that the tutorial was completed, then the client will
refresh. Returns either a response or None. """
# unpack some variables
experiment, worker, override = [
context[k] for k in ['experiment', 'worker', 'override']]
if (request.method == "GET" and experiment.has_tutorial and
(override == "tut" or not is_preview_request(request))):
show_tutorial = (override == "tut" or
not context['experiment_worker'].tutorial_completed)
if show_tutorial:
context.update(csrf(request))
template_name = experiment.template_name()
return render(request, '%s_tut.html' % template_name, context)
elif (request.method == "POST" and override is None and
'tutorial_complete' in request.POST and
request.POST['tutorial_complete'] == 'true'):
ew_id = context['experiment_worker'].id
ExperimentWorker.objects.filter(id=ew_id) \
.update(tutorial_completed=True)
return json_success_response()
return None
示例8: external_task_GET
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def external_task_GET(request, context):
""" Handles GETs for mturk tasks. Returns a response. """
# unpack some variables
override, experiment = [context[k] for k in ['override', 'experiment']]
# template name is based on experiment parameters
if experiment.variant:
variant = json.loads(experiment.variant)
else:
variant = None
context['variant'] = variant
# template names
template_name = experiment.template_name()
context['instructions'] = '%s_inst_content.html' % template_name
context['content_thumb_template'] = '%s_thumb.html' % template_name
# fetch examples from database
publishable = override and 'publishable' in request.GET
external_task_prepare_examples(
context, experiment, publishable=publishable)
# add extra context depending on the task
external_task_extra_context(experiment.slug, context)
# decide if we need feedback
external_task_prepare_feedback(request, context)
if override == "task" or not is_preview_request(request):
context.update(csrf(request))
return render(request, '%s.html' % template_name, context)
else:
return render(request, '%s_inst.html' % template_name, context)
示例9: home
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.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
示例10: signup
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def signup(request):
"""
Display the signup form.
"""
csrf_token = csrf(request)['csrf_token']
if request.user.is_authenticated():
return redirect('/course/')
if settings.FEATURES.get('AUTH_USE_CERTIFICATES_IMMEDIATE_SIGNUP'):
# Redirect to course to login to process their certificate if SSL is enabled
# and registration is disabled.
return redirect_with_get('login', request.GET, False)
return render_to_response('register.html', {'csrf': csrf_token})
示例11: login_page
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def login_page(request):
"""
Display the login form.
"""
csrf_token = csrf(request)['csrf_token']
if (settings.FEATURES['AUTH_USE_CERTIFICATES'] and
ssl_get_cert_from_request(request)):
# SSL login doesn't require a login view, so redirect
# to course now that the user is authenticated via
# the decorator.
next_url = request.GET.get('next')
if next_url:
return redirect(next_url)
else:
return redirect('/course/')
if settings.FEATURES.get('AUTH_USE_CAS'):
# If CAS is enabled, redirect auth handling to there
return redirect(reverse('cas-login'))
return render_to_response(
'login.html',
{
'csrf': csrf_token,
'forgot_password_link': "//{base}/login#forgot-password-modal".format(base=settings.LMS_BASE),
'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME),
}
)
示例12: post
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def post(self, request, **kwargs):
password1 = request.POST.get('password1', '')
password2 = request.POST.get('password2', '')
current_password = request.POST.get('current_pasword', '')
user = User.objects.get(id=request.user.id)
context = {
'breadcrumbs': [
{'name': 'My Account', 'url': reverse('account')},
{'name': 'Change Password', },
]
}
if not user.check_password(current_password):
context.update(csrf(request))
mssg = "Your current password is incorrect"
messages.add_message(request, messages.INFO, mssg)
return TemplateResponse(request, self.template_name, context)
if password1 and password2:
if password1 == password2:
user.set_password(password1)
user.save()
mssg = "Password Successfully Changed!"
else:
context.update(csrf(request))
mssg = "Password Mismatch"
messages.add_message(request, messages.INFO, mssg)
return TemplateResponse(request, self.template_name, context)
if not password1 and not password2:
context.update(csrf(request))
mssg = "Passwords should match or field should not be left empty"
else:
context.update(csrf(request))
mssg = "Passwords should match or field should not be left empty"
messages.add_message(request, messages.INFO, mssg)
return TemplateResponse(request, self.template_name, context)
示例13: get
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def get(self, request, *args, **kwargs):
"""Handles GET requests to the 'account_forgot_password' named route.
Returns: A forgot-password template rendered to a HttpResponse.
"""
context = {
'page_title': 'Forgot Password',
'email_form': EmailForm(auto_id=True),
}
context.update(csrf(request))
return render(request, 'authentication/forgot_password.html', context)
示例14: post
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def post(self, request, *args, **kwargs):
"""Handles POST requests to 'account_reset_password' named route.
Returns: A HttpResponse with the reset_password template.
"""
reset_password_form = ResetPasswordForm(request.POST, auto_id=True)
if reset_password_form.is_valid():
try:
# get the recovery_user from the session:
recovery_user_pk = request.session['recovery_user_pk']
user = User.objects.get(pk=recovery_user_pk)
# change the user's password to the new password:
new_password = reset_password_form.cleaned_data.get('password')
user.set_password(new_password)
user.save()
# inform the user through a flash message:
messages.add_message(
request, messages.INFO,
'Your password was changed successfully!')
# redirect the user to the sign in:
return redirect(reverse('signin'))
except ObjectDoesNotExist:
# set an error message:
messages.add_message(
request, messages.ERROR,
'You are not allowed to perform this action!')
return HttpResponse('Action not allowed!', status_code=403)
context = {
'page_title': 'Reset Password',
'reset_password_form': reset_password_form,
}
context.update(csrf(request))
return render(request, 'authentication/reset_password.html', context)
示例15: new_transaksi_member
# 需要导入模块: from django.core import context_processors [as 别名]
# 或者: from django.core.context_processors import csrf [as 别名]
def new_transaksi_member(self, request):
if request.user.is_anonymous():
return HttpResponseRedirect('/accounts/login')
BukuFormSet = inlineformset_factory(models.Transaksi, models.Buku, form=BukuForm, extra=1)
FotoFormSet = inlineformset_factory(models.Transaksi, models.Foto_Bukti_Pembayaran, form=Foto_Bukti_PembayaranForm, extra=1)
transaksi = models.Transaksi()
if request.method == 'GET':
form = TransaksiForm(instance=transaksi)
formset_buku = BukuFormSet(instance=transaksi)
formset_foto = FotoFormSet(instance=transaksi)
else:
form = TransaksiForm(request.POST, request.FILES, instance=transaksi)
formset_buku = BukuFormSet(request.POST, request.FILES, instance=transaksi)
formset_foto = FotoFormSet(request.POST, request.FILES, instance=transaksi)
if form.is_valid() and formset_buku.is_valid() and formset_foto.is_valid():
form.save()
formset_buku.save()
formset_foto.save()
success_msg = "Transaksi Berhasil Dibuat!"
args = {
'user': request.user,
'new_transaksi_member_form': form,
'formset_buku': formset_buku,
'formset_foto': formset_foto,
'request': request,
'success_msg': success_msg
}
args.update(csrf(request))
args['form'] = form
return render_to_response('new_transaksi_member.html', args)
args = {
'user': request.user,
'new_transaksi_member_form': form,
'formset_buku': formset_buku,
'formset_foto': formset_foto,
'request': request
}
args.update(csrf(request))
args['form'] = form
return render_to_response('new_transaksi_member.html', args)
#-----------templates/add-transaksi.html------------------
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:51,代码来源:django inlineformset_factory add remove.py