Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FileField returns relative url (instead of absolute) inside serialized data returned by SerializerMethodField #9620

Unanswered
ZeroAurora asked this question in Potential Issue
Discussion options

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?

You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

Have you tried to set the MEDIA_URL setting from Django to your base URL?

You must be logged in to vote
4 replies
Comment options

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...

Comment options

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...

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.

Comment options

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?

Comment options

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /