0

Background:

I have uploaded a xls file using the FileField. Now I want to parse this file using the xlrd tool.

While doing so I am doing the following in the view.

if form.is_valid():
            user_file = form.save()
            user_file.save()             
            workbook = xlrd.open_workbook(user_file.file.name)//( user_file.file.name returns relative path to the media_root folder. )
            sheet = workbook.sheet_by_index(0)

This gives an error as xlrd is unable to find the file.(As the path is not absolute). How can I do this ?

Akash Deshpande
  • 2,583
  • 10
  • 41
  • 82

1 Answers1

2
os.path.join(settings.MEDIA_ROOT, user_file.file.name)

Should give the correct path.

Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116