I've built a script to read an excel file and save the contents into my database. (Note: the file and the script are in different directories). However, when I try to execute the script from my views.py as a simple import, django throws an error that it cannot find the file or directory:
[Errno 2] No such file or directory: '\\media\\documents\\GDRAT.xls\\'
My actual code in the script looks like this:
source_wb = xlrd.open_workbook('media/documents/GDRAT.xls')
Where my script is in the parent directory. Executing the script from the command line works just fine, so I'm struggling with why django is reading it differently.
My views.py
function looks like this (Note: I go back to the parent directory to find the script - which seems to work fine, just can't find the excel file I need to read in):
def UpdateGDRAT(request):
os.chdir('..')
import GDRAT
return render_to_response('success.html')
Any guidance is greatly appreciated!
This works for me
os.path.join(os.path.dirname(os.path.dirname(__file__)),'media/documents/GDRAT.xls')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With