[英]“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.