· 5 years ago · Mar 05, 2020, 12:20 PM
1import os
2import dj_database_url
3from dotenv import load_dotenv
4load_dotenv(verbose=True)
5
6# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
7BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8
9# Quick-start development settings - unsuitable for production
10# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
11
12# import configurations
13MAPS_API_KEY = os.getenv("MAPS_API_KEY")
14SECRET_KEY = os.getenv("SECRET_KEY")
15DATABASE_NAME = os.getenv("DATABASE_NAME")
16DATABASRE_USERNAME = os.getenv("DATABASRE_USERNAME")
17DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD")
18
19# SECURITY WARNING: don't run with debug turned on in production!
20DEBUG = True
21
22ALLOWED_HOSTS = ['127.0.0.1', '.herokuapp.com', "localhost"]
23
24# Application definition
25INSTALLED_APPS = [
26 'django.contrib.admin',
27 'django.contrib.auth',
28 'django.contrib.contenttypes',
29 'django.contrib.sessions',
30 'django.contrib.messages',
31 'django.contrib.staticfiles',
32 'home',
33 'crispy_forms',
34 'phone_field',
35 'bootstrap4',
36 'bootstrap_datepicker_plus',
37 'visits',
38]
39
40MIDDLEWARE = [
41 'django.middleware.security.SecurityMiddleware',
42 'whitenoise.middleware.WhiteNoiseMiddleware',
43 'django.contrib.sessions.middleware.SessionMiddleware',
44 'django.middleware.common.CommonMiddleware',
45 'django.middleware.csrf.CsrfViewMiddleware',
46 'django.contrib.auth.middleware.AuthenticationMiddleware',
47 'django.contrib.messages.middleware.MessageMiddleware',
48 'django.middleware.clickjacking.XFrameOptionsMiddleware',
49]
50
51ROOT_URLCONF = 'base.urls'
52
53TEMPLATES = [
54 {
55 'BACKEND': 'django.template.backends.django.DjangoTemplates',
56 'DIRS': [os.path.join(BASE_DIR, 'home/templates')],
57 'APP_DIRS': True,
58 'OPTIONS': {
59 'context_processors': [
60 'django.template.context_processors.debug',
61 'django.template.context_processors.request',
62 'django.contrib.auth.context_processors.auth',
63 'django.contrib.messages.context_processors.messages',
64 'visits.context_processors.request_meta',
65 ],
66 },
67 },
68]
69
70WSGI_APPLICATION = 'base.wsgi.application'
71
72# Database
73# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
74
75# DATABASES = {
76# 'default': {
77# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
78# 'NAME': DATABASE_NAME,
79# 'USER': DATABASRE_USERNAME,
80# 'PASSWORD': DATABASE_PASSWORD,
81# 'HOST': 'localhost',
82# 'PORT': '',
83# }
84# }
85
86DATABASES = {
87 'default': {
88 'ENGINE': 'django.db.backends.sqlite3',
89 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
90 }
91}
92
93# Heroku Configuration
94db_from_env = dj_database_url.config(conn_max_age=500)
95DATABASES['default'].update(db_from_env)
96
97# Password validation
98# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
99
100AUTH_PASSWORD_VALIDATORS = [
101 {
102 'NAME':
103 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
104 },
105 {
106 'NAME':
107 'django.contrib.auth.password_validation.MinimumLengthValidator',
108 },
109 {
110 'NAME':
111 'django.contrib.auth.password_validation.CommonPasswordValidator',
112 },
113 {
114 'NAME':
115 'django.contrib.auth.password_validation.NumericPasswordValidator',
116 },
117]
118
119# Internationalization
120# https://docs.djangoproject.com/en/2.0/topics/i18n/
121
122LANGUAGE_CODE = 'en-us'
123
124TIME_ZONE = 'Africa/Nairobi'
125
126USE_I18N = True
127
128USE_L10N = True
129
130USE_TZ = True
131
132AUTH_USER_MODEL = 'home.User'
133
134# user redirected to home after successful login
135LOGIN_REDIRECT_URL = '/'
136LOGOUT_REDIRECT_URL = '/'
137EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
138
139# Static files (CSS, JavaScript, Images)
140# https://docs.djangoproject.com/en/2.0/howto/static-files/
141
142STATIC_URL = '/static/'
143STATIC_ROOT = os.path.join(BASE_DIR, 'static')
144STATICFILES_DIRS = [os.path.join(BASE_DIR, 'home/static')]
145
146MEDIA_URL = '/media/'
147MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
148
149CRISPY_TEMPLATE_PACK = 'bootstrap4'
150
151BOOTSTRAP4 = {
152 'include_jquery': True,
153}
154# Django Visits Configuration
155MIN_TIME_BETWEEN_VISITS = 1