-
-
Notifications
You must be signed in to change notification settings - Fork 7k
FileField returns relative url (instead of absolute) inside serialized data returned by SerializerMethodField #9620
-
Example code: https://github.com/ZeroAurora/drf-nested-file-serializaion-issue
When returning a serializer's data from a SerializerMethodField, the FileField of the serializer returns a relative url . However I guess it should be an absolute one, because when the model containing the file is directly serialized, the returning data contains an absolute url.
The problem above is demonstrated in the README.
Is it expected or a bug?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 4 replies
-
Have you tried to set the MEDIA_URL
setting from Django to your base URL?
Beta Was this translation helpful? Give feedback.
All reactions
-
So I added some tests to reproduce the problem and defined the setting to fix it: ZeroAurora/drf-nested-file-serializaion-issue#1
While it fixes the problem, I agree that it's strange that the MediaFileSerializer
behaves differently if the InnerSerializer
is nested inside another one...
Beta Was this translation helpful? Give feedback.
All reactions
-
So I added some tests to reproduce the problem and defined the setting to fix it: ZeroAurora/drf-nested-file-serializaion-issue#1
While it fixes the problem, I agree that it's strange that the
MediaFileSerializer
behaves differently if theInnerSerializer
is nested inside another one...
Did a quick test in workspace and that does fix the problem
I discovered this problem while doing my school assignments, and in that project MEDIA_URL
was defined (as a relative path) but still produced the same problem.
Beta Was this translation helpful? Give feedback.
All reactions
-
in that project
MEDIA_URL
was defined (as a relative path) but still produced the same problem.
So to be clear, when you said you had "the same problem", do you mean that you had a mix of absolute and relative URLs or were all URLs relative?
Beta Was this translation helpful? Give feedback.
All reactions
-
So to be clear, when you said you had "the same problem", do you mean that you had a mix of absolute and relative URLs or were all URLs relative?
Yes the first one, similar to the example I provided
Beta Was this translation helpful? Give feedback.