如何通过Serializer传递文件的URL

时间:2018-03-02 09:36:28

标签: python django django-rest-framework django-serializer

我创建了这样的模型:

class ArtistSerializer (serializers.ModelSerializer):
    class Meta:
        model = Artist
        fields = ('name' , )

有一个图像文件,现在,我想通过一个串行器传递每个模型的图像URL并将其作为json发布我的Serializer现在是这样的:

$('.row').sortable();
$('div.container').froalaEditor({
    toolbarInline: true,
    toolbarButtons: ['fullscreen', 'bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', '|', 'fontFamily', 'fontSize', 'color', 'inlineStyle', 'paragraphStyle', '|', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', '-', 'insertLink', 'insertImage', 'insertVideo', 'embedly', 'insertFile', 'insertTable', '|', 'emoticons', 'specialCharacters', 'insertHR', 'selectAll', 'clearFormatting', '|', 'print', 'spellChecker', 'help', 'html', '|', 'undo', 'redo'],
    toolbarButtonsXS: null,
    toolbarButtonsSM: null,
    toolbarButtonsMD: null
  });

但我不知道该怎么做。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您使用

FileField(max_length=None, allow_empty_file=False, use_url=UPLOADED_FILES_USE_URL)

use_url - 如果设置为True,则URL字符串值将用于输出表示。

相关问题