如何使用Cloudinary在Django项目中强制HTTPS?

时间:2018-01-29 19:37:46

标签: django cloudinary

我在我的Django项目中使用Cloudinary来上传和存储我的图像。

这样的事情:

mymodel = MyModel.objects.get(pk=1)
return mymodel.logo.url

在我的序列化程序中,如果我打电话给:

$ head path3/list?
==> path3/list1 <==
1
2
3

==> path3/list2 <==
10
11
12


$ cat path3/list? | while read -r f; do touch path3/"$f".xml; done

$ ls path3
1.xml  10.xml  11.xml  12.xml  2.xml  3.xml  list1  list2

返回的是一个cloud url url但只有http。我该如何解决?我如何获得https?

3 个答案:

答案 0 :(得分:1)

Cloudinary响应包含ITU_R_601_4 true false (HTTP)和url(HTTPS)。

请尝试:

secure_url

而不是

return mymodel.logo.secure_url

答案 1 :(得分:0)

对于遇到secure_url错误的人,修改url_options字典对我来说是成功的秘诀:

mymodel = MyModel.objects.get(pk=1)
# Adding 'secure' to url_options
# Cloudinary source code seems to look for this key when building urls
mymodel.logo.url_options.update({'secure':True})
return mymodel.logo.url

答案 2 :(得分:0)

在设置中设置secure

cloudinary.config(cloud_name = "", api_key = "", api_secret = "", secure = True)