错误:无法上传图片,请尝试另一个 Forbidden(CSRF 令牌丢失或不正确。):/fileUpload
视图.py
@requires_csrf_token
def upload_image_view(request):
f = request.FILES['image']
fs = FileSystemStorage()
filename = "blog/"+str(f).split('.')[0]
file = fs.save(filename, f)
fileurl = fs.url(file)
return JsonResponse({'success': 1, 'file': {'url': fileurl}})
网址.py
path('fileUpload',csrf_exempt(upload_image_view)),