uploading a file but did not get a file name

I have a code, its working but it does not return a actual name of file


def upload_file(request):
    getusername = ''
    getfirstname = ''  
    getemail = ''
    getpassword = ''

    if request.method == 'POST':
        getusername = request.POST['username']
        getfirstname = request.POST['first_name']

def handle_uploaded_file(f):

    destination = open('media/filename', 'wb+')
    for chunk in f.chunks(): filename = form.clean_data['file'].name    
        getemail =  request.POST['email']
        form = UploadFileForm(request.POST, request.FILES)
        filename = request.FILES['file']

def handle_uploaded_file(f):

    destination = open('media/filename', 'wb+')
    for chunk in f.chunks(): 

In forms.py

filename = form.clean_data['file'].name    



in your handle_uploaded_file(f) it would be f.name

source: https://docs.djangoproject.com/en/1.6/topics/http/file-uploads/#handling-uploaded-files

Your source should look similar to this:

def upload_file(request):
    if request.method == 'POST':
        form = YourForm(request.POST, request.FILES)
        if form.is_valid():            
            data = loginForm.cleaned_data
            username = data['username']
            first_name = data['first_name']
            #you can retrieve the filename here
            filename = request.FILES['file'].name            
            return HttpResponseRedirect('/success/url/')
        form = YourForm()

    return render_to_response('your.html', {'form': form})

def handle_uploaded_file(f):
    #or here
    filename = f.name
    with open('some/file/name.txt', 'wb+') as destination:
        for chunk in f.chunks():

Need Your Help

Can not set a selector to background of RadioButton

android radio-button drawable

I got a strange error when I try to set a selector to background of RadioButton.

Magento Widget does not appear on Newsletter

php magento widget newsletter

I am having a trouble on Magento CE 1.7 when dealing with Newsletters.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.