Skip to content

Commit 3211332

Browse files
committed
Unsaved file objects may not have an associated URL.
1 parent 9b8f966 commit 3211332

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/fields.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,12 @@ def to_internal_value(self, data):
11981198
return data
11991199

12001200
def to_representation(self, value):
1201+
if not value:
1202+
return None
1203+
12011204
if self.use_url:
1202-
if not value:
1205+
if not getattr(value, 'url', None):
1206+
# If the file has not been saved it may not have a URL.
12031207
return None
12041208
url = value.url
12051209
request = self.context.get('request', None)

0 commit comments

Comments
 (0)