如何在local_settings.py中关闭django积云

时间:2022-03-01 20:37:48

I have taken over a project that uses django cumulus for cloud storage. On my development machine, some times I use a slow internet connection, and every time I save a change, django recompiles and tries to make a connection to the racksapace store

我接管了一个使用django积云进行云存储的项目。在我的开发机器上,有时我使用慢速互联网连接,每次我保存更改,django重新编译并尝试连接到racksapace商店

Starting new HTTPS connection (1): identity.api.rackspacecloud.com

This sometimes takes 15 seconds and is a real pain. I read a post where someone said they turned off cumulus for local development. I think this was done by setting

这有时需要15秒,这是一个真正的痛苦。我看了一篇帖子,有人说他们关闭了积累以进行本地开发。我认为这是通过设置来完成的

DEFAULT_FILE_STORAGE

but unfortunately the poster did not specify. If someone knows a simple setting I can put in my local settings to serve media and static files from my local machine and stop django trying to connect to my cloud storage on every save, that is what I want to do.

但不幸的是海报没有说明。如果有人知道一个简单的设置,我可以放入我的本地设置来从我的本地机器上提供媒体和静态文件,并停止django试图在每次保存时连接到我的云存储,这就是我想要做的。

2 个解决方案

#1


0  

Yeah it looks like you should just need the DEFAULT_FILE_STORAGE to be default value, which is django.core.files.storage.FileSystemStorage according to the source code.

是的,看起来你应该只需要DEFAULT_FILE_STORAGE作为默认值,根据源代码是django.core.files.storage.FileSystemStorage。

However, a better approach would be to not set anything in your local settings and set the DEFAULT_FILE_STORAGE and CUMULUS in a staging_settings.py or prod_settings.py file.

但是,更好的方法是不在本地设置中设置任何内容,并在staging_settings.py或prod_settings.py文件中设置DEFAULT_FILE_STORAGE和CUMULUS。

#2


0  

The constant reloading of the rackspace bucket was because the previous developer had

机架空间桶的不断重新装载是因为之前的开发人员

from cumulus.storage import SwiftclientStorage
class PrivateStorage(SwiftclientStorage):

and in models.py

并在models.py中

from common.storage import PrivateStorage
PRIVATE_STORE = PrivateStorage()
...
class Upload(models.Model):
    upload = models.FileField(storage=PRIVATE_STORE, upload_to=get_upload_path)

This meant every time the project reloaded, it would create a new https connection to rackspace, and time out if the connection was poor. I created a settings flag to control this by putting the import of SwiftclientStorage and defining of PrivateStorage like so

这意味着每次重新加载项目时,它都会创建一个到rackspace的新https连接,如果连接很差,则会超时。我创建了一个设置标志来控制它,方法是将SwiftclientStorage导入并定义为PrivateStorage

from django.conf import settings
if settings.USECUMULUS:
    from cumulus.storage import SwiftclientStorage

    class PrivateStorage(SwiftclientStorage):
...
else:
    class PrivateStorage():
        pass

#1


0  

Yeah it looks like you should just need the DEFAULT_FILE_STORAGE to be default value, which is django.core.files.storage.FileSystemStorage according to the source code.

是的,看起来你应该只需要DEFAULT_FILE_STORAGE作为默认值,根据源代码是django.core.files.storage.FileSystemStorage。

However, a better approach would be to not set anything in your local settings and set the DEFAULT_FILE_STORAGE and CUMULUS in a staging_settings.py or prod_settings.py file.

但是,更好的方法是不在本地设置中设置任何内容,并在staging_settings.py或prod_settings.py文件中设置DEFAULT_FILE_STORAGE和CUMULUS。

#2


0  

The constant reloading of the rackspace bucket was because the previous developer had

机架空间桶的不断重新装载是因为之前的开发人员

from cumulus.storage import SwiftclientStorage
class PrivateStorage(SwiftclientStorage):

and in models.py

并在models.py中

from common.storage import PrivateStorage
PRIVATE_STORE = PrivateStorage()
...
class Upload(models.Model):
    upload = models.FileField(storage=PRIVATE_STORE, upload_to=get_upload_path)

This meant every time the project reloaded, it would create a new https connection to rackspace, and time out if the connection was poor. I created a settings flag to control this by putting the import of SwiftclientStorage and defining of PrivateStorage like so

这意味着每次重新加载项目时,它都会创建一个到rackspace的新https连接,如果连接很差,则会超时。我创建了一个设置标志来控制它,方法是将SwiftclientStorage导入并定义为PrivateStorage

from django.conf import settings
if settings.USECUMULUS:
    from cumulus.storage import SwiftclientStorage

    class PrivateStorage(SwiftclientStorage):
...
else:
    class PrivateStorage():
        pass