我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用django.conf.settings.DATABASE_ROUTERS。
def configure(self): shards = dict() nodes = django_settings.DJANGO_AUTOSHARD.NODES for node in nodes: try: _ = node['HOST'] except KeyError: raise exceptions.ImproperlyConfigured('Node {} does not have a host.'.format(node)) try: _ = node['RANGE'] except KeyError: raise exceptions.ImproperlyConfigured('Node {} does not specify a shard range.'.format(node)) node_shards = self.set_logical_shards(node) shards.update(node_shards) django_settings.SHARDS = OrderedDict(sorted(shards.items())) django_settings.DATABASE_ROUTERS = ('django_autoshard.routers.ShardRouter', )
def __init__(self, routers=None): """ If routers is not specified, will default to settings.DATABASE_ROUTERS. """ self._routers = routers
def routers(self): if self._routers is None: self._routers = settings.DATABASE_ROUTERS routers = [] for r in self._routers: if isinstance(r, six.string_types): router = import_string(r)() else: router = r routers.append(router) return routers