[英]Forbidden 403 CSRF verification failed. Request aborted. drf
i am trying to upload image with drf:我正在尝试使用 drf 上传图像:
urls.py:网址.py:
path('eventimageupload/<int:category>/', views.EventImageUploadView.as_view()),
views.py:视图.py:
class EventImageUploadView(generics.ListCreateAPIView):
authentication_classes = []
permission_classes = []
def post(self, request,category):
file = request.data['file']
data={
'image':file,
'category_id':category,
}
EventsImage.objects.create(**data)
return JsonResponse(json.dumps({'message': "Uploaded"}), status=200, safe=False)
its working good on localhost but from server its getting this error它在本地主机上运行良好,但从服务器收到此错误
you need to allow cross request call您需要允许交叉请求调用
https://pypi.org/project/django-cors-headers/
check above library, add that into your middleware检查上面的库,将其添加到您的中间件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.