Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The below code provides a few different ways of specifying database settings, including allowing old, Django 1.2-style <code>DATABASE_FOO</code> declarations:</p> <pre><code># Settings with no underscores in their names apply to the "default" # database out-of-the-box DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = 'foo.sqlite' DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = '' # Since this setting has underscores in it, it needs to be specified the # long way to disambiguate DATABASE_default_SUPPORTS_TRANSACTIONS = True # Specifying any settings for a database will implicitly copy everything # else from default. DATABASE_baz_NAME = 'baz.sqlite' # Databases can also be defined with Django 1.2-style dicts DATABASE_bar = { 'NAME': 'bar.sqlite', } # Empty dicts will create complete clones of default DATABASE_clone = {} </code></pre> <p>...and here's the implementation:</p> <pre><code>databases = {} database_global_settings = set([ 'DATABASE_ROUTERS', ]) current_settings = globals() for (k, v) in current_settings.items(): if k in database_global_settings: continue if k.startswith('DATABASE_'): if k.count('_') &gt;= 2: (dummy_label, dbname, variable) = k.split('_', 2) if not dbname in databases: databases[dbname] = {} databases[dbname][variable] = v elif isinstance(v, dict): (dummy_label, dbname) = k.split('_', 1) if dbname in databases: databases[dbname].update(v) else: databases[dbname] = v else: # legacy configuration for default database dbname = 'default' (dummy_label, variable) = k.split('_', 1) if not dbname in databases: databases[dbname] = {} databases[dbname][variable] = v del globals()[k] for database_name in databases: if database_name != 'default': for (k, v) in databases['default'].iteritems(): databases[database_name].setdefault(k, v) DATABASES = databases </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload