确保在http_method_names中有“POST”。或者,您可以这样写: defallowed_methods(self):""" Return the list of allowed HTTP methods, uppercased. """self.http_method_names.append("post")return[method.upper()formethodinself.http_method_namesifhasattr(self, method)]...
跑着一个论坛,需要向HTML页面提交POST数据,结果都被拦截下来了,显示错误:“nginx 405 Not Allowed”...
Nginx的405 not allowed错误解决
如果要获取所有的POST数据,可以使用request.POST.dict()方法将POST数据转换为字典。例如: def my_view(request): if request.method == 'POST': post_data = request.POST.dict() # 获取所有的POST数据 # 进行其他操作... return HttpResponse('Success') else: return HttpResponse('Method not allowed') ...
有时候,我们想要限制访问的请求方法,比如我们希望用户只能通过get方式请求,post不允许,那么我们可以采用装饰器的方式,django已经为我们提供了内置的装饰器 限制请求装饰器 Django内置的视图装饰器可以给视图提供一些限制。比如这个视图只能通过GET的method访问等。
Method not allowed 错误是因为它在您的 API 类中搜索 get() 方法,但找不到。 API类的一般格式如下 class LocationView(views.APIView): def get(self, request): #do something with 'GET' method return Response("some data") def post(self, request): #do something with 'POST' method return Respo...
Error: Method Not Allowed If @router.get('/{str:name}') put in the back, put is work, but post and patch can't work 👍 1 Sorry, something went wrong. Copy link Owner vitalik commented Jun 7, 2022 • edited Loading @wu-clan well this basically handled by Django urls......
msg='405_METHOD_NOT_ALLOWED', success=False) if 500 <= response.status_code <= 599: response = RestResponse(data=response.data, code=response.status_code, status=response.status_code, msg='INTERNAL_SERVER_ERROR', success=False) return response setting.py注册handler, 1 2 3 4 5 6 7 { ...
POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR)) if to_field and not self.to_field_allowed(request, to_field): raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field) model = self.model opts = model._meta if request.method == 'POST' and '_saveas...
def post(self, request, format=None): print(request.method) return Response('ok') def put(self, request, format=None): print(request.method) return Response('ok') """ 1. 先获取分类的名字 2. 根据分类的名字,在分类表中,获取键 3