Django settings.py

Posted under » MySQL » Django on 23 April 2021

From Installing mod_wsgi for django we know we have to

ALLOWED_HOSTS = ['student.com']
WSGI_APPLICATION = 'student_als.wsgi.application'

Now we have to

TIME_ZONE = 'Asia/Singapore'
This 'TIME_ZONE' will not work in combination 'USE_TZ' unless you are in America or UTC time.
USE_TZ = True # must be deleted if from SG.

Switch from SQlite to mysql with this

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'dbblog',
        'USER': 'tidak',
        'PASSWORD': 't35nang12',
        'HOST': 'localhost',   
        'PORT': '3306',
    }    
}

You can add another database of a different type too perhaps a read only one?

DATABASES = {
    'default': {
        "ENGINE": "django.db.backends.mysql",
        'NAME': 'bridev',
        'USER': 'rasa',
        'PASSWORD': 'sentosa',
        'HOST': 'localhost',   
        'PORT': '3306',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
        }
    },
    'light': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

For any new app created. Take note the case for the Config, it is
'polls.apps.PollsConfig' and not 'polls.apps.pollsConfig'.

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'polls.apps.PollsConfig',
'napi.apps.NapiConfig',
]

You can make URL alias like

LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'innerpage'

You have to give email settings for your user change password to work.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'bill@gates.edu.sg'
EMAIL_HOST_PASSWORD = 'MrLK1sUgly'
DEFAULT_FROM_EMAIL = 'Mr. Softee <whgates@gates.edu.sg>'

This is quite similar to phpmailer settings.

Static files

STATIC_URL = '/static/'
STATIC_ROOT = "/var/www/dblog/static/"

More on Static files.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data