2016-03-05 29 views
1

在我的Django應用程序的models.py中,我寫了一個自定義的Storage類,稱爲OverwriteStorage。它的目的是上傳並從我使用的第三方存儲桶中獲取靜態對象(Azure)。在Django網絡應用程序的models.py中訪問用戶uri方案

在其他方面,此自定義存儲類定義了一個名爲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協議方案?我的Django網絡應用程序接受httphttps協議,並且我想將相關協議附加到此方法返回的url。

回答

1

我認爲這裏的正確的解決方法就是使用相對協議網址,如rfc3986描述:

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