How can I find the path to tempfile in django

I use pdftk like this

pdftk template.pdf fill_form /temp/input.fdf output /temp/output.pdf

Now it works fine

But now I created a temporary file instead of /temp/input.fdf with this

 myfile = tempfile.NamedTemporaryFile() myfile.write(fdf) myfile.seek(0) myfile.close() 

Now I do not know how I can pass myfile as input to pdftk

+4
source share
2 answers

myfile.name will give you the file path.

Note that tempfile does not exist after close() . From the docs:

  tempfile.TemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None]]]]]) 

Returns a file-like object that can be used as a temporary storage area. The file is created using mkstemp (). It will be destroyed as soon as it closes (including implicit closure when the object is garbage collection). On Unix, the directory entry for the file is deleted immediately after the file is created. Other platforms do not support this; Your code should not rely on the temporary file created using this function, with or without a visible name in the file system.

Source: http://docs.python.org/2/library/tempfile.html

+6
source

Unable to get name using

 myfile = tempfile.NamedTemporaryFile() myfile.write(fdf) myfile.seek(0) myfile.close() print(myfile.name) 
+6
source

All Articles