Reputation: 1640
beginner question. here's pdb output
(Pdb) entry.image
<FieldFile: None>
(Pdb) entry.image is None
False
how do I check if the image exists or not?
Lets say I want to access entry.image.file but I dont know whether entry.image exists
SOLVED check my own answer
Upvotes: 1
Views: 622
Reputation: 74705
How about:
import os
os.path.exists(file_path) and os.path.isfile(file_path)
Upvotes: 0
Reputation: 87095
Here:
file_path = entry.image.path
open(file_path)
If the file exists, there should not be any error.
Upvotes: 0