我有一个带有图像的模型新闻,这些新闻可以通过JSON REST API加载.服务器使用来自管理局的证书进行签名,所有请求必须使用https完成.
我的问题是,ModelSerializer使用http而不是https序列化ImageField.我该如何改变?
这是代码和输出示例的摘要:
#myProject/models.py
class News(models.Model):
image = models.ImageField()
#myProject/serializers.py
class NewsSerializer(serializers.ModelSerializer):
class Meta:
model = News
fields = ('image')
#request for a news
https://myDomain/news/the-news-id-here/
#current output
{
"image": "http://myDomain/media/news/imageName.jpg"
}
#wanted output
{
"image": "https://myDomain/media/news/imageName.jpg"
}
Run Code Online (Sandbox Code Playgroud)
谢谢大卫
我正在使用这个xlsx js库从 Angular5 应用程序中的 TypeScript 对象列表生成 Excel 文件。
我不需要 TypeScript 对象的所有属性,我想以特定方式对其他属性进行排序。
以一个简单的 TypeScript 对象列表为例:
[
{
"id":"one",
"location":"New York",
"metadata":"just other infos",
"name":"John",
},
{
"id":"two",
"location":"Boston",
"metadata":"just other infos",
"name":"Mark",
},
{
"id":"three",
"location":"Portland",
"metadata":"just other infos",
"name":"Samy",
}
]
Run Code Online (Sandbox Code Playgroud)
想要Excel输出:
|id |name |location |
|one |John |New York |
|two |Mark |Boston |
|three |Samy |Portland |
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的(排序没问题):
const workbook = XLSX.utils.book_new();
const myHeader = ["id","name","location"];
const worksheet = XLSX.utils.json_to_sheet(this.myListOfObjects(), {header: myHeader});
XLSX.utils.book_append_sheet(workbook, worksheet, 'tab1');
XLSX.writeFile(workbook, …
Run Code Online (Sandbox Code Playgroud)