本文整理汇总了Python中django.http.HttpResponseNotAllowed方法的典型用法代码示例。如果您正苦于以下问题:Python http.HttpResponseNotAllowed方法的具体用法?Python http.HttpResponseNotAllowed怎么用?Python http.HttpResponseNotAllowed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http
的用法示例。
在下文中一共展示了http.HttpResponseNotAllowed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contacts_new
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def contacts_new(request):
if request.method != 'POST':
return HttpResponseNotAllowed(('POST',))
data = {
key: value for key, value in request.POST.items()
if key in ('name', 'fone', 'email')
}
contact = Contact.objects.create(**data)
response = dict(
name=contact.name,
avatar=contact.avatar(),
email=contact.email,
phone=contact.fone
)
return JsonResponse(response, status=201)
示例2: dispatch
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def dispatch(self, request, url):
if not url:
url = '/'
if request.method not in self.http_method_names:
return http.HttpResponseNotAllowed(request.method)
if not self._can_access_kibana():
error_msg = (_('User %s does not have sufficient '
'privileges to access Kibana')
% auth_utils.get_user(request))
LOG.error(error_msg)
return http.HttpResponseForbidden(content=error_msg)
# passing kbn version explicitly for kibana >= 4.3.x
headers = {
"X-Auth-Token": request.user.token.id,
"kbn-version": request.META.get("HTTP_KBN_VERSION", ""),
"Cookie": request.META.get("HTTP_COOKIE", ""),
"Content-Type": "application/json",
}
return self.read(request.method, url, request.body, headers)
示例3: require_http_methods
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def require_http_methods(request_method_list):
"""
Decorator to make a view only accept particular request methods. Usage::
@require_http_methods(["GET", "POST"])
def my_view(request):
# I can assume now that only GET or POST requests make it this far
# ...
Note that request methods should be in uppercase.
"""
def decorator(func):
@wraps(func)
def inner(request, *args, **kwargs):
if request.method not in request_method_list:
logger.warning(
'Method Not Allowed (%s): %s', request.method, request.path,
extra={'status_code': 405, 'request': request}
)
return HttpResponseNotAllowed(request_method_list)
return func(request, *args, **kwargs)
return inner
return decorator
示例4: webhook
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def webhook(request, build_key):
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
try:
data = json.loads(request.body)
except ValueError:
err_str = "Bad json in github webhook request"
logger.warning(err_str)
return HttpResponseBadRequest(err_str)
user = models.GitUser.objects.filter(build_key=build_key).first()
if not user:
logger.warning("No user with build key %s" % build_key)
return HttpResponseBadRequest("Error")
if user.recipes.count() == 0:
logger.warning("User '%s' does not have any recipes" % user)
return HttpResponseBadRequest("Error")
return process_event(user, data)
示例5: do_branch_page
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def do_branch_page(request, branch):
"""
Render the branch page given a branch object
Input:
request[django.http.HttpRequest]
branch[models.Branch]
"""
if request.method != "GET":
return HttpResponseNotAllowed(['GET'])
causes = []
if request.GET.get("do_filter", "0") == "0":
causes = [models.Event.PUSH, models.Event.MANUAL, models.Event.RELEASE]
form = forms.BranchEventsForm(initial={"filter_events": causes})
else:
form = forms.BranchEventsForm(request.GET)
if form.is_valid():
causes = [int(c) for c in form.cleaned_data["filter_events"]]
event_list = EventsStatus.get_default_events_query().filter(base__branch=branch, cause__in=causes)
events = get_paginated(request, event_list)
evs_info = EventsStatus.multiline_events_info(events)
return render(request, 'ci/branch.html', {"form": form, 'branch': branch, 'events': evs_info, 'pages': events})
示例6: activate_job
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def activate_job(request, job_id):
"""
Endpoint for activating a job
"""
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
job = get_object_or_404(models.Job, pk=job_id)
server = job.recipe.repository.server()
user = server.signed_in_user(request.session)
if not user:
raise PermissionDenied('You need to be signed in to activate a job')
collab = Permissions.is_collaborator(request.session, job.event.build_user, job.recipe.repository, user=user)
if collab:
if set_job_active(request, job, user):
job.init_pr_status()
job.event.make_jobs_ready()
else:
raise PermissionDenied('Activate job: {} is NOT a collaborator on {}'.format(user, job.recipe.repository))
return redirect('ci:view_job', job_id=job.pk)
示例7: cancel_job
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def cancel_job(request, job_id):
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
job = get_object_or_404(models.Job, pk=job_id)
allowed = Permissions.is_collaborator(request.session, job.event.build_user, job.event.base.repo())
if not allowed:
return HttpResponseForbidden('Not allowed to cancel this job')
signed_in_user = job.event.base.server().signed_in_user(request.session)
message = "Canceled by %s" % signed_in_user
comment = escape(request.POST.get('comment'))
post_to_pr = request.POST.get('post_to_pr') == 'on'
if post_to_pr:
post_job_change_to_pr(request, job, "canceled", comment, signed_in_user)
if comment:
message += "\nwith comment: %s" % comment
set_job_canceled(job, message)
UpdateRemoteStatus.job_complete(job)
logger.info('Job {}: {} on {} canceled by {}'.format(job.pk, job, job.recipe.repository, signed_in_user))
messages.info(request, 'Job {} canceled'.format(job))
return redirect('ci:view_job', job_id=job.pk)
示例8: update_remote_job_status
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def update_remote_job_status(request, job_id):
"""
End point for manually update the remote status of a job.
This is needed since sometimes the git server doesn't
get updated properly due to timeouts, etc.
"""
job = get_object_or_404(models.Job.objects, pk=job_id)
allowed = Permissions.is_collaborator(request.session, job.event.build_user, job.event.base.repo())
if request.method == "GET":
return render(request, 'ci/job_update.html', {"job": job, "allowed": allowed})
elif request.method == "POST":
if allowed:
UpdateRemoteStatus.job_complete_pr_status(job)
else:
return HttpResponseNotAllowed("Not allowed")
return redirect('ci:view_job', job_id=job.pk)
示例9: upload_symbols
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def upload_symbols(request):
if request.method != 'POST':
return HttpResponseNotAllowed('Only POST here')
form = UploadSymbolsForm(request.POST, request.FILES)
if not form.is_valid():
logger.error("form is invalid with error: " + str(form.errors))
return HttpResponseNotAllowed('Invalid data')
path = handle_uploaded_file(request.FILES['symbols'])
upload = SymbolsUploadHandler()
upload.process(form.cleaned_data, path)
return HttpResponse("Success")
示例10: upload_file
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def upload_file(request):
if request.method != 'POST':
return HttpResponseNotAllowed('Only POST here')
form = UploadFileForm(request.POST, request.FILES)
if not form.is_valid():
logger.error("form is invalid with error: " + str(form.errors))
return HttpResponseBadRequest()
file = request.FILES['upload_file_minidump']
try:
crash_id = str(create_database_entry(file, form))
except (InvalidVersionException) as e:
logger.error("invalid version exception " + str(e))
return HttpResponseServerError(str(e))
logger.info("uploaded crash: " + crash_id)
return HttpResponse('Crash-ID=%s'%(crash_id))
# vim:set shiftwidth=4 softtabstop=4 expandtab: */
示例11: require_http_methods
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def require_http_methods(request_method_list):
"""
Decorator to make a view only accept particular request methods. Usage::
@require_http_methods(["GET", "POST"])
def my_view(request):
# I can assume now that only GET or POST requests make it this far
# ...
Note that request methods should be in uppercase.
"""
def decorator(func):
@wraps(func)
def inner(request, *args, **kwargs):
if request.method not in request_method_list:
response = HttpResponseNotAllowed(request_method_list)
log_response(
'Method Not Allowed (%s): %s', request.method, request.path,
response=response,
request=request,
)
return response
return func(request, *args, **kwargs)
return inner
return decorator
示例12: require_http_methods
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def require_http_methods(request_method_list):
"""
Decorator to make a view only accept particular request methods. Usage::
@require_http_methods(["GET", "POST"])
def my_view(request):
# I can assume now that only GET or POST requests make it this far
# ...
Note that request methods should be in uppercase.
"""
def decorator(func):
@wraps(func, assigned=available_attrs(func))
def inner(request, *args, **kwargs):
if request.method not in request_method_list:
logger.warning(
'Method Not Allowed (%s): %s', request.method, request.path,
extra={'status_code': 405, 'request': request}
)
return HttpResponseNotAllowed(request_method_list)
return func(request, *args, **kwargs)
return inner
return decorator
示例13: require_http_methods
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def require_http_methods(request_method_list):
"""
Decorator to make a view only accept particular request methods. Usage::
@require_http_methods(["GET", "POST"])
def my_view(request):
# I can assume now that only GET or POST requests make it this far
# ...
Note that request methods should be in uppercase.
"""
def decorator(func):
@wraps(func, assigned=available_attrs(func))
def inner(request, *args, **kwargs):
if request.method not in request_method_list:
logger.warning('Method Not Allowed (%s): %s', request.method, request.path,
extra={
'status_code': 405,
'request': request
}
)
return HttpResponseNotAllowed(request_method_list)
return func(request, *args, **kwargs)
return inner
return decorator
示例14: authoring_tool_auth
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def authoring_tool_auth(f):
def g(request):
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
# Get the task and question and check permissions.
task = get_object_or_404(Task, id=request.POST["task"])
if not task.has_write_priv(request.user):
return HttpResponseForbidden()
if not task.module.is_authoring_tool_enabled(request.user):
return HttpResponseForbidden()
# Run inner function.
return f(request, task)
return g
示例15: post
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseNotAllowed [as 别名]
def post(self, request, type, submission_pk):
if not request.is_ajax():
return HttpResponseNotAllowed()
# Only staff can create staff flags.
if type == self.model.STAFF and not self.request.user.is_apply_staff:
return HttpResponseNotAllowed()
submission_type = ContentType.objects.get_for_model(ApplicationSubmission)
# Trying to get a flag from the table, or create a new one
flag, created = self.model.objects.get_or_create(user=request.user, target_object_id=submission_pk, target_content_type=submission_type, type=type)
# If no new flag has been created,
# Then we believe that the request was to delete the flag.
if not created:
flag.delete()
return JsonResponse({"result": created})