本文整理汇总了Python中django.template.response.TemplateResponse.status_code方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateResponse.status_code方法的具体用法?Python TemplateResponse.status_code怎么用?Python TemplateResponse.status_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.response.TemplateResponse
的用法示例。
在下文中一共展示了TemplateResponse.status_code方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unauthed
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def unauthed(self, request):
response = TemplateResponse(
request=request,
template='aldryn_sso/basicauth_auth_required.html',
content_type='text/html',
)
response['WWW-Authenticate'] = 'Basic realm="Protected"'
response.status_code = 401
return response
示例2: challenge
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def challenge(self, request):
realm = getattr(settings, 'API_AUTH_REALM', 'Restricted access')
response = TemplateResponse(
request,
'api/401.html'
)
response['WWW-Authenticate'] = 'Basic realm="%s"' % realm
response.status_code = 401
return response
示例3: _create_403_response
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def _create_403_response(self, request, operation, resource, authority=None, template_name=None, message=None):
template_name = template_name or '403.html'
response = TemplateResponse(request, template_name, {
'operation': operation,
'resource': resource,
'authority': authority,
'message': message,
'status_code': '403'
})
response.status_code = 403
return response
示例4: post
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def post(self, request):
if request.POST['ik_pm_no']:
payment_id = request.POST['ik_pm_no']
payment = Payment.objects.get(paymentid=payment_id)
payment.status = request.POST['ik_inv_st']
payment.system = request.POST['ik_pw_via']
payment.amount = request.POST['ik_am']
payment.save()
self.sendmail(payment)
response = TemplateResponse(
request, self.get_template(payment), {'payment': payment, 'link': self.get_link(payment), })
response.status_code = '200'
return response
示例5: confirmed
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def confirmed(request):
comment = None
if 'c' in request.GET:
try:
comment = get_model().objects.get(pk=request.GET['c'])
except ObjectDoesNotExist:
pass
response = TemplateResponse(request, template, {
'comment': comment,
'is_ajax': is_ajax,
'success' : True
})
response.status_code = comment.is_public and 201 or 202
return response
示例6: simple_browse
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def simple_browse(request):
response_code = None
context = {}
try:
objs = _objects_by_type(REPO.SimpleCollection, SimpleCollection)
objs = sorted(objs, key=lambda s: s.label)
context['objs'] = objs
except RequestFailed:
response_code = 500
# FIXME: this is duplicate logic from generic search view
context['server_error'] = 'There was an error ' + \
'contacting the digital repository. This ' + \
'prevented us from completing your search. If ' + \
'this problem persists, please alert the ' + \
'repository administrator.'
response = TemplateResponse(request, 'collection/simple_browse.html', context)
if response_code is not None:
response.status_code = response_code
return response
示例7: handle_error
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def handle_error(request):
response = TemplateResponse(request, 'page/500.html', {})
response.status_code = 500
return response.render()
示例8: page_not_found
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def page_not_found(request):
response = TemplateResponse(request, 'page/404.html', {})
response.status_code = 404
return response.render()
示例9: _get_forbidden_rsponse
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
def _get_forbidden_rsponse(request):
response = TemplateResponse(request, "403.html")
response.status_code = HttpResponseForbidden.status_code
return response
示例10: send_oauth_error
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import status_code [as 别名]
except OAuthError, ex:
return send_oauth_error(ex)
if request.method == 'GET':
response = TemplateResponse(
request,
'api/auth/oauth/authorise.html',
{
'form': AuthoriseForm(),
'app': app,
'no_login_form': True,
'popup': True
}
)
response.status_code = 401
response.realm = 'API'
return response
elif request.method == 'POST':
callback = app.callback_url
form = AuthoriseForm(data = request.POST)
if request.user.is_authenticated():
token = oauth_server.authorize_token(token, request.user)
if callback:
args = '?%s' % token.to_string(only_key = True)
return HttpResponseRedirect(callback + args)
else:
return HttpResponse(token.to_string(only_key = True), mimetype = 'text/plain')