Wednesday, April 29, 2015

upload csv file from different directories

Hi I am writing an app that upload csv file and write csv data to models. So far everything is working fine. What i want to do now is to be able get the users to be able to upload csv files from different directories.  I cannot seem to figure this out, i need directions. form the  function csvimport is there are a way to get the user select the file from different directories, instead of hard coding the path (with open('/var/www/html/webapp/csvupload/data1.csv')

here is my codes.

def showuploadform(request):
    if request.method=='POST':
        form = uploadform(request.POST, request.FILES)
        if form.is_valid():
            return render_to_response('csv_test.html',locals())
        form = uploadform()
    return render(request,'uploadform.html',{'form': form})

def csvimport(request):
    with open('/var/www/html/webapp/csvupload/data1.csv','rb') as csvfile:
        readata=csv.reader(csvfile,delimiter=',', quotechar='"')
        for row in readata:
            if row[0] != 'PersonID':
        return render_to_response('csv_test.html',locals())

class uploadform(forms.Form):


<form enctype="multipart/form-data" action ="/showuploadform/" method="post">{%csrf_token%}
<input type="submit" name="submit" value="Upload Files" > 


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment