本文整理汇总了Python中django.template.response.TemplateResponse方法的典型用法代码示例。如果您正苦于以下问题:Python response.TemplateResponse方法的具体用法?Python response.TemplateResponse怎么用?Python response.TemplateResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.response
的用法示例。
在下文中一共展示了response.TemplateResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: require_confirmation
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def require_confirmation(func):
"""
Decorator to lead to a confirmation page.
This has been used rather than simply adding the same lines
in action functions inorder to avoid repetition of the same
lines in the two added actions and more actions
incase they are added in future.
"""
def wrapper(modeladmin, request, queryset):
opts = modeladmin.model._meta
if request.POST.get('confirmation') is None:
request.current_app = modeladmin.admin_site.name
context = {
'action': request.POST['action'],
'queryset': queryset,
'opts': opts,
}
return TemplateResponse(
request, 'admin/action_confirmation.html', context
)
return func(modeladmin, request, queryset)
wrapper.__name__ = func.__name__
return wrapper
示例2: post
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def post(self, request, *args, **kwargs):
form = self.password_reset_form(request.POST)
if form.is_valid():
opts = {
'use_https': request.is_secure(),
'token_generator': self.password_reset_token_generator,
'email_template_name': self.password_reset_email_template,
'request': request,
'domain_override': request.get_host()
}
if self.password_reset_from_email:
opts['from_email'] = self.password_reset_from_email
if self.password_reset_subject_template:
opts['subject_template_name'] = self.password_reset_subject_template
form.save(**opts)
context = super(ResetPasswordSendView, self).get_context()
return TemplateResponse(request, self.password_reset_done_template, context)
else:
return self.get(request, form=form)
示例3: html_print
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def html_print(request, queryset):
model = queryset.model
opts = model._meta
action = sys._getframe().f_code.co_name
action_name = "打印"
verify = queryset.values('status').order_by('status').distinct()
if verify.count() > 1:
mesg = "不允许打印多个不同状态的 {}".format(opts.verbose_name)
return mesg
extra_for = queryset.count() - 10 < 0
if extra_for:
extra_for = list(range(abs(queryset.count() - 10)))
_extra = dict(
extra_for=extra_for,
ticket=int(time.time()),
)
context = construct_context(request, queryset, action, action_name)
context.update(_extra)
templates = ["%s/print.html" % (opts.model_name), "base/print.html"]
return TemplateResponse(request, templates, context)
示例4: movedown
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def movedown(request, queryset):
action = sys._getframe().f_code.co_name
action_name = "下架"
if request.POST.get('post'):
for obj in queryset:
o = copy.deepcopy(obj)
obj.actived = False
obj.status = 'offline'
obj.operator = request.user
obj.units.all().update(actived=True, operator=obj.operator)
obj.pdus.all().update(actived=True, operator=obj.operator)
obj.save()
diffs = diff_dict(model_to_dict(o), model_to_dict(obj))
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk, action_flag=action_name,
message=json.dumps(list(diffs.keys())),
content=json.dumps(diffs)
)
return None
context = construct_context(request, queryset, action, action_name)
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例5: actived
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def actived(request, queryset):
action = sys._getframe().f_code.co_name
action_name = "停用"
if request.POST.get('post'):
for obj in queryset:
o = copy.deepcopy(obj)
obj.actived = False
obj.save()
diffs = diff_dict(model_to_dict(o), model_to_dict(obj))
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk,
action_flag="停用",
message=json.dumps(list(diffs.keys())),
content=json.dumps(diffs)
)
return None
context = construct_context(request, queryset, action, action_name)
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例6: reclaim
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def reclaim(request, queryset):
action = sys._getframe().f_code.co_name
action_name = "回收"
if request.POST.get('post'):
for obj in queryset:
o = copy.deepcopy(obj)
obj.actived = False
obj.save()
diffs = diff_dict(model_to_dict(o), model_to_dict(obj))
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk,
action_flag=action_name,
message=json.dumps(list(diffs.keys())),
content=json.dumps(diffs)
)
return None
context = construct_context(request, queryset, action, action_name)
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例7: reactive
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def reactive(request, queryset):
action = sys._getframe().f_code.co_name
action_name = "启用"
if request.POST.get('post'):
for obj in queryset:
o = copy.deepcopy(obj)
obj.actived = True
obj.save()
diffs = diff_dict(model_to_dict(o), model_to_dict(obj))
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk,
action_flag=action_name,
message=json.dumps(list(diffs.keys())),
content=json.dumps(diffs)
)
return None
context = construct_context(request, queryset, action, action_name)
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例8: reoutbound
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def reoutbound(request, queryset):
action = sys._getframe().f_code.co_name
action_name = "取消出库"
queryset = queryset.filter(actived=False)
if not queryset.exists():
return "查无结果"
if request.POST.get('post'):
for obj in queryset:
o = copy.deepcopy(obj)
obj.actived = True
obj.save()
diffs = diff_dict(model_to_dict(o), model_to_dict(obj))
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk,
action_flag=action_name,
message=json.dumps(list(diffs.keys())),
content=json.dumps(diffs)
)
return None
context = construct_context(request, queryset, action, action_name)
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例9: index
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
req_protocol = request.scheme
req_site = get_current_site(request)
sites = []
for section, site in sitemaps.items():
if callable(site):
site = site()
protocol = req_protocol if site.protocol is None else site.protocol
sitemap_url = urlresolvers.reverse(
sitemap_url_name, kwargs={'section': section})
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
sites.append(absolute_url)
for page in range(2, site.paginator.num_pages + 1):
sites.append('%s?p=%s' % (absolute_url, page))
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
示例10: render_delete_form
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def render_delete_form(self, request, context):
opts = self.model._meta
app_label = opts.app_label
request.current_app = self.admin_site.name
context.update(
to_field_var=TO_FIELD_VAR,
is_popup_var=IS_POPUP_VAR,
)
return TemplateResponse(request,
self.delete_confirmation_template or [
"admin/{}/{}/delete_confirmation.html".format(app_label, opts.model_name),
"admin/{}/delete_confirmation.html".format(app_label),
"admin/delete_confirmation.html"
], context)
示例11: password_reset_done
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def password_reset_done(request,
template_name='registration/password_reset_done.html',
current_app=None, extra_context=None):
context = {
'title': _('Password reset sent'),
}
if extra_context is not None:
context.update(extra_context)
if current_app is not None:
request.current_app = current_app
return TemplateResponse(request, template_name, context)
# Doesn't need csrf_protect since no-one can guess the URL
示例12: sql
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def sql(request):
databases = connections.databases.keys()
query = request.GET.get("query")
db = request.GET.get("database")
if query and db:
cursor = connections[db].cursor()
cursor.execute(query, [])
results = cursor.fetchall()
return TemplateResponse(
request,
"sql.html",
{"query": query, "rows": results, "databases": databases},
)
else:
return TemplateResponse(
request, "sql.html", {"query": None, "rows": None, "databases": databases}
)
示例13: detail_zeppelin_job
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def detail_zeppelin_job(request, id):
"""
View to show the details for the scheduled Zeppelin job with the given ID.
"""
spark_job = get_object_or_404(SparkJob, pk=id)
response = ""
if spark_job.results:
markdown_url = "".join(
[x for x in spark_job.results["data"] if x.endswith("md")]
)
bucket = settings.AWS_CONFIG["PUBLIC_DATA_BUCKET"]
markdown_file = spark_job.provisioner.s3.get_object(
Bucket=bucket, Key=markdown_url
)
response = markdown_file["Body"].read().decode("utf-8")
context = {"markdown": response}
return TemplateResponse(
request, "atmo/jobs/zeppelin_notebook.html", context=context
)
示例14: index
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
req_protocol = request.scheme
req_site = get_current_site(request)
sites = [] # all sections' sitemap URLs
for section, site in sitemaps.items():
# For each section label, add links of all pages of its sitemap
# (usually generated by the `sitemap` view).
if callable(site):
site = site()
protocol = req_protocol if site.protocol is None else site.protocol
sitemap_url = reverse(sitemap_url_name, kwargs={'section': section})
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
sites.append(absolute_url)
# Add links to all pages of the sitemap.
for page in range(2, site.paginator.num_pages + 1):
sites.append('%s?p=%s' % (absolute_url, page))
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
示例15: index
# 需要导入模块: from django.template import response [as 别名]
# 或者: from django.template.response import TemplateResponse [as 别名]
def index(self, request, extra_context=None):
"""
Display the main admin index page, which lists all of the installed
apps that have been registered in this site.
"""
app_list = self.get_app_list(request)
context = dict(
self.each_context(request),
title=self.index_title,
app_list=app_list,
)
context.update(extra_context or {})
request.current_app = self.name
return TemplateResponse(request, self.index_template or 'admin/index.html', context)