So, I have a issue that i cant find a solution for. I am developing an application using Django where my front end has to be in angular-js. Now I am able to render forms and also post the data from the forms, but i have no idea how to upload a file using these forms.
This is my code:
in urls.py
url(r'^getter/$', TemplateView.as_view(template_name = "upload.html"))
url(r'^getter/test/', views.test, name = "thanks.html")
in views.py
def test(request):
upload_form = uploadform(request.POST, request.FILES)
data = json.loads(request.body)
file_path = data.path
in forms.py
select_file = forms.FileField(label = "Choose File")
in my js file inside my controller
myapp.controller('abc', function ($scope, $http)
$scope.submit = function(){
var file = document.getElementById('id_select_file').value
var json = {file : string(file)}
$http.post('test/',json)
...success fn....
...error fn...
}; });
Now the issue is that if in my view if i do
f = request.FILES['select_file']
I get error 'select_file' not found in MultiValueDict: {}
probably the issue is that with the way am sending my post request am not sending all the meta data....please help me out with this i have spent the whole day looking for a solution but no avail.
PS: for some restriction policies I can not use Djangular so please give me solutions that donot use djangular. Thanks
Edit: **Applying file properties to the json that the server is receiving doesnt work either **