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 youtube 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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…