Answer the question
In order to leave comments, you need to log in
How to upload a file using DRF + VueJS?
JS
new Vue({
delimiters: ["{>", "<}"],
el: '#import_tokens',
data() {
return {
file: null,
}
},
methods: {
sendFile: function () {
var self = this
console.log(this.file)
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'
axios.put(
'http://' + window.location.host + '/api/tokens_VMP_excel/',
self.file,
{
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function (response) {
}).catch(function (error) {
console.log(error);
});
}
},
created: function () {
}
})
class TokensVMPExcelViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = TokenVMPExcel.objects.all()
serializer_class = TokensVMPExcelSerializer
parser_classes = (MultiPartParser,)
def put(self, request):
print (request.FILES)
return Response(status=204)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question