# Django Settings
Modifying the message tags - for convenience
MESSAGE_TAGS = {
messages.DEBUG: 'info',
messages.INFO: 'info',
messages.SUCCESS: 'success',
messages.WARNING: 'warning',
messages.ERROR: 'danger',
}
Template Location and template tags
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'libraries':{
'filename': 'yourproject.templatetags',
'file_exists': 'yourproject.templatetags',
}
},
},
]
Inside the templatetags.py file - Same Directory as yourproject
import os
from django import template
from django.core.files.storage import default_storage
register = template.Library()
@register.filter
def filename(value):
return os.path.basename(value.file.name)
@register.filter
def file_exists(value):
if default_storage.exists(value):
return True
else:
return False
Databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'databasename',
'USER': 'databaseuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
Timezone
TIME_ZONE = 'Africa/Johannesburg'
Media and static files
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
MEDIA_URL = '/uploads/'
SMTP Configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'email.host'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'hi@email.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'hi@email.com'
Login and redirect url
LOGIN_REDIRECT_URL = 'dashboard'
LOGIN_URL = 'login'
Django Resized
DJANGORESIZED_DEFAULT_SIZE = [500, 500]
DJANGORESIZED_DEFAULT_QUALITY = 75
DJANGORESIZED_DEFAULT_KEEP_META = True
DJANGORESIZED_DEFAULT_NORMALIZE_ROTATION = True
DJANGORESIZED_DEFAULT_FORMAT_EXTENSIONS = {'PNG': ".png"}
If you are using TinyMCE with FileBrowser
TINYMCE_FILEBROWSER = True
X_FRAME_OPTIONS = 'SAMEORIGIN'
FILEBROWSER_DIRECTORY = ''
DIRECTORY = ''
# Timezone Stuff
When you need to use timezone aware datetime objects in the python code
import datetime
import pytz
#time aware datetime
d_time = datetime.datetime.now(pytz.timezone('Africa/Johannesburg'))
print(d_time)
Output
datetime.datetime(2021, 8, 24, 22, 39, 59, 974842, tzinfo=<DstTzInfo 'Africa/Johannesburg' SAST+2:00:00 STD>)