Created
May 16, 2012 18:10
-
-
Save juanriaza/2712702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.forms import forms | |
from django.core.urlresolvers import reverse | |
from django.http import HttpResponseRedirect | |
from django.shortcuts import render | |
class TestForm(forms.Form): | |
my_file = forms.FileField() | |
def handle_uploaded_file(file): | |
destination = open('%s/%s' % (settings.PROJECT_ROOT, file.name), 'wb+') | |
for chunk in file.chunks(): | |
destination.write(chunk) | |
destination.close() | |
def home(request): | |
if request.method == 'POST': | |
form = TestForm(request.POST, request.FILES) | |
if form.is_valid(): | |
handle_uploaded_file(request.FILES['my_file']) | |
return HttpResponseRedirect(reverse('blog')) | |
else: | |
form = TestForm() | |
return render(request, "binnary/test.html", {'form': form}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment