有没有人有任何关于直接使用azang-storage与Django的提示?我问,因为目前我正在尝试为我的Django应用程序设置Azure云存储(使用Ubuntu OS托管在Azure VM上),并且django-storages
似乎没有正确地与Azure Storage SDK连接(已知问题:请参阅此处).鉴于我的Django版本<1.6.2,那里列出的修复程序对我不起作用.
因此,我需要直接使用Azure存储与Django.有人有过这样的话吗?我需要在云存储上保存图像和mp3.
目前,在我的models.py中,我有:
def upload_to_location(instance, filename): try: blocks = filename.split('.') ext = blocks[-1] filename = "%s.%s" % (uuid.uuid4(), ext) instance.title = blocks[0] return os.path.join('uploads/', filename) except Exception as e: print '%s (%s)' % (e.message, type(e)) return 0 class Photo(models.Model): description = models.TextField(validators=[MaxLengthValidator(500)]) submitted_on = models.DateTimeField(auto_now_add=True) image_file = models.ImageField(upload_to=upload_to_location, null=True, blank=True )
然后django-storages
,boto
照顾其余的.但是,当我使用Azure云存储挂起django-storage时,我收到以下错误:
Exception Value: 'module' object has no attribute 'WindowsAzureMissingResourceError' Exception Location: /home/mhb11/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/storages/backends/azure_storage.py in exists, line 46
代码的相关片段是:
def exists(self, name): try: self.connection.get_blob_properties( self.azure_container, name) except azure.WindowsAzureMissingResourceError: return False else: return True
似乎与Azure容器的连接失败.在我的settings.py中,我有:
DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage' AZURE_ACCOUNT_NAME = 'photodatabasestorage' AZURE_ACCOUNT_KEY = 'something' AZURE_CONTAINER = 'somecontainer'
如前所述,我需要一个完全绕过django-storage的解决方案,并且只依靠Azure Storage SDK来完成工作.
注意:如果您需要,请向我询问更多信息.