简体   繁体   English

“详细信息”:“方法 \”GET\“ 不允许。” Django Rest 框架

[英]“detail”: “Method \”GET\“ not allowed.” Django Rest Framework

I know this question was duplicate I am beginner in django I tried in all ways but not able to find solution I was trying to upload a file and get a json response as ok using django rest framework I know this question was duplicate I am beginner in django I tried in all ways but not able to find solution I was trying to upload a file and get a json response as ok using django rest framework

So far I tried is到目前为止我尝试的是

views.py:视图.py:

from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.response import Response
from rest_framework import status
from .serializers import FileSerializer

class FileView(APIView):
  parser_classes = (MultiPartParser, FormParser)
  

  def post(self, request, *args, **kwargs):
    file_serializer = FileSerializer(data=request.data)
    if file_serializer.is_valid():
      file_serializer.save()
      return Response(file_serializer.data, status=status.HTTP_201_CREATED)
    else:
      return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)

urls.py:网址.py:

from django.conf.urls import url
from .views import FileView

urlpatterns = [
    url(r'^upload/$', FileView.as_view(), name='file-upload'),
    url(r'^upload/<int:pk>/$', FileView.as_view(), name='file-upload'),
]

The error is:错误是:

Method /GET/ is not allowed方法 /GET/ 不允许

please help me thanks in advance请帮助我提前谢谢

If you can have a look at your view.py file, You don't have any GET method and this is why it is not able to call the URL with GET request.如果您可以查看您的 view.py 文件,您没有任何 GET 方法,这就是它无法使用 GET 请求调用 URL 的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &quot;detail&quot;: &quot;方法 \\&quot;GET\\&quot; 不允许。&quot; 在 TokenAuthentication Django 休息框架中 - "detail": "Method \"GET\" not allowed." in TokenAuthentication Django rest framework "detail": "方法 \"GET\" 不允许。" Django Rest 框架 - "detail": "Method \"GET\" not allowed." Django Rest Framework Django REST 框架 - “方法 \”GET\“ 不允许。” - - Django REST framework - “Method \”GET\“ not allowed.” - { &quot;detail&quot;: &quot;方法 \\&quot;GET\\&quot; 不允许。&quot; } - { "detail": "Method \"GET\" not allowed." } django“详细信息”:“方法\\”GET\\“不允许。” (一对多关系) - django “detail”: “Method \”GET\“ not allowed.” (one to many relationship) “详细信息”:“方法 \\”GET\\” 不允许。在 Django 中调用端点 - “detail”: “Method \”GET\" not allowed. on calling endpoint in django DRF- Django Rest 框架 re_path 查询参数 - “方法 \”GET\“ 不允许。” - DRF- Django Rest Framework re_path query params - “Method \”GET\“ not allowed.” DRF:“详细信息”:“方法\\” GET \\“不允许。” - DRF: “detail”: “Method \”GET\“ not allowed.” POST 返回“详细信息”:“不允许使用方法 \"GET\"。” - POST returns "detail": "Method \"GET\" not allowed." &quot;detail&quot;: &quot;方法 \\&quot;POST\\&quot; 不允许。&quot; - "detail": "Method \"POST\" not allowed."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM