newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save
Let say I upload the file xyz.csv which make newdoc or docfile as
newdoc=xyz.csv or docfile=xyz.csv
I want to do:
changedoc = xyz.txt
i.e. I want to remove the extension and give it .txt extension
How I can play with it?
I just need to extract the name only not the file itself.
解决方案
Read the file name from request.FILES['docfile'].name, use os.path.splitext() to get the file name without extension:
docfile = request.FILES['docfile']
filename = os.path.splitext(docfile.name)[0]
newfilename = 'ok_%s.txt' % filename