【问题标题】:Accessing user uri scheme in models.py in Django web app在 Django Web 应用程序的 models.py 中访问用户 uri 方案
【发布时间】:2016-06-19 14:29:31
【问题描述】:

在我的 Django 应用程序的 models.py 中,我编写了一个名为 OverwriteStorage 的自定义 Storage 类。它的目的是从我使用的第 3 方存储桶(Azure)上传和获取静态对象。

除此之外,此自定义存储类定义了一个名为 url 的方法,其中:

def url(self, name):
    """
    Returns the URL where the contents of the file referenced by name can
    be accessed.
    """
    url = '%s/%s/%s' % ('http://example.blob.core.windows.net','mypictures', name)
    return url

此方法实质上返回上传到 Azure 存储 blob 上的静态对象的位置。

我的问题是,有没有办法访问访问存储类的用户的 http-protocol 方案?我的 Django Web 应用程序接受 httphttps 协议,我想将相关协议附加到此方法返回的 url。

【问题讨论】:

    标签: python django python-2.7 django-models


    【解决方案1】:

    我认为这里正确的解决方案是只使用协议相对 URL,如 rfc3986 中所述:

    return '%s/%s/%s' % ('//example.blob.core.windows.net', 'mypictures', name)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-06
      • 2011-07-01
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多