I have a django app which has a file upload feature. I am currently using forms in an HTML template, instead of using django forms. my current code is as follows:
views.py
def new(request):
file_path = 'c:\\Users\\Me\\Desktop\\'+request.POST['myFile']
newFile = DjangoFile(file(file_path))
obj = MyObj(myFile=newFile)
obj.save()
according to this code, i had to specify the base file path in order to read it and save it in the MEDIA_ROOT directory. Is there any way I can read the path of the file being uploaded, instead of providing a hard coded base path?
My html template has the following code:
<p>My File: <input type="file" name="myFile" class="form-control input-md-4" id="myFile" /></p><br />