How to format django settings.py correctly?

I am a beginner of django and read "Practical django projects". The book states the following:

DATABASE_ENGINE = β€˜sqlite3β€²

However, the settings.py DATABASES file uses the dictionary instead -

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

Is this a different version, or am I mistaken? Also, please offer any online tutorials that you think will help me learn django.

+3
source share
2 answers

The tutorial you are running is for Django <= 1.1, in 1.2 they changed the format of the database parameters to allow the use of all new multiple databases. If your tutorial tells you to create something like this:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/path/to/your/dev.db'

, sqlite3 1.2:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/path/to/your/dev.db',
    }
}

. Django , , 1.1, docs .

+6

, . 1.2 ( , ). Django . .

+1

Source: https://habr.com/ru/post/1788681/


All Articles