[英]How to force HTTPS in a Django project using Cloudinary?
I am using Cloudinary in my Django project to upload and store my images.我在我的 Django 项目中使用 Cloudinary 来上传和存储我的图像。
Something like this:像这样的东西:
class MyModel(models.Model):
logo = CloudinaryField('Logo', blank=True, null=True)
In my serializers, if I call something like:在我的序列化程序中,如果我调用类似的东西:
mymodel = MyModel.objects.get(pk=1)
return mymodel.logo.url
What is being returned is a cloudinary url but only with http.返回的是一个cloudinary url,但只有http。 How do I fix this?
我该如何解决这个问题? How do I get https?
我如何获得https?
The Cloudinary response holds both url
(HTTP) and secure_url
(HTTPS). Cloudinary 响应包含
url
(HTTP) 和secure_url
(HTTPS)。
Please try:请尝试:
return mymodel.logo.secure_url
Instead of而不是
return mymodel.logo.url
在设置中设置secure
:
cloudinary.config(cloud_name = "", api_key = "", api_secret = "", secure = True)
For anyone that's getting errors with secure_url
, modifying the url_options
dictionary did the trick for me:对于任何在
secure_url
上遇到错误的secure_url
,修改url_options
字典对我来说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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.