I'm trying to create a form that will handle video file uploads from the user, but I'm running into a bunch of problems. I am trying to avoid building a model form for this because I won't be saving the file to my database long term. I just want to get it to the server so that I can submit it to youtube. The html I have is:
<form method='post' action='/new/' enctype="multi-part/form-data">{% csrf_token %}
<input type='file' name='file' id='file'/>
<input type='submit' />
</form>
and then the view attempts to handle the file like so:
def create_video(request):
if request.method == 'POST':
video = request.POST['file']
command=subprocess.Popen('youtube-upload --email=' + email + ' --password=' + password + '--title=' + title + ' --description=' + description + ' --category=Sports ' + video, stdout=subprocess.PIPE)
vid = command.stdout.read()
# do stuff to save video instance to database
return show_video(request, video.id)
else:
form=Video()
return render_to_response('create_video.html', RequestContext(request, locals()))
note: youtube-upload is a python module to upload videos to y开发者_如何转开发outube with that given command.
So for starters when I submit the form from the front end django sends a message saying "Key 'file' not found in <QueryDict:...
and given that I fix the form so that it will submit properly is the rest of the view properly handling the file?
request.POST
doesn't contain file upload information. You need to use request.FILES
.
精彩评论