|
1 |
| -""" |
2 |
| -Django settings for SeeMe_be project. |
3 |
| -
|
4 |
| -Generated by 'django-admin startproject' using Django 5.1.1. |
5 |
| -
|
6 |
| -For more information on this file, see |
7 |
| -https://docs.djangoproject.com/en/5.1/topics/settings/ |
8 |
| -
|
9 |
| -For the full list of settings and their values, see |
10 |
| -https://docs.djangoproject.com/en/5.1/ref/settings/ |
11 |
| -""" |
12 |
| - |
13 | 1 | from pathlib import Path
|
| 2 | +from decouple import config, Csv |
| 3 | +from datetime import timedelta |
14 | 4 |
|
15 |
| -# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 5 | +# Base directory of the project |
16 | 6 | BASE_DIR = Path(__file__).resolve().parent.parent
|
17 | 7 |
|
18 |
| - |
19 |
| -# Quick-start development settings - unsuitable for production |
20 |
| -# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ |
21 |
| - |
22 |
| -# SECURITY WARNING: keep the secret key used in production secret! |
23 |
| -SECRET_KEY = 'django-insecure-5hex$m9=j7f&ur7xe3qh$t^3_6!#yc)uymrkmii)hz$z^9$yzx' |
24 |
| - |
25 |
| -# SECURITY WARNING: don't run with debug turned on in production! |
26 |
| -DEBUG = True |
27 |
| - |
28 |
| -ALLOWED_HOSTS = ["*","127.0.0.1"] |
29 |
| - |
| 8 | +# Environment configurations |
| 9 | +SECRET_KEY = config('SECRET_KEY') |
| 10 | +DEBUG = config('DEBUG', default=False, cast=bool) |
| 11 | +ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='', cast=Csv()) |
30 | 12 |
|
31 | 13 | # Application definition
|
32 |
| - |
33 | 14 | INSTALLED_APPS = [
|
| 15 | + 'daphne', |
34 | 16 | 'django.contrib.admin',
|
35 | 17 | 'django.contrib.auth',
|
36 | 18 | 'django.contrib.contenttypes',
|
37 | 19 | 'django.contrib.sessions',
|
38 | 20 | 'django.contrib.messages',
|
39 | 21 | 'django.contrib.staticfiles',
|
40 |
| - #installed |
| 22 | + # Third-party apps |
41 | 23 | 'rest_framework',
|
42 | 24 | 'rest_framework_simplejwt',
|
43 | 25 | 'django_filters',
|
44 |
| - 'corsheaders', |
| 26 | + 'corsheaders', |
45 | 27 | 'django_extensions',
|
46 | 28 | 'channels',
|
47 |
| - #my models |
| 29 | + 'django_redis', |
| 30 | + # Custom apps |
48 | 31 | 'users',
|
49 | 32 | 'vendor',
|
50 | 33 | 'authentication',
|
|
55 | 38 | ]
|
56 | 39 |
|
57 | 40 | MIDDLEWARE = [
|
58 |
| - 'corsheaders.middleware.CorsMiddleware', |
| 41 | + 'corsheaders.middleware.CorsMiddleware', |
59 | 42 | 'django.middleware.security.SecurityMiddleware',
|
60 | 43 | 'django.contrib.sessions.middleware.SessionMiddleware',
|
61 | 44 | 'django.middleware.common.CommonMiddleware',
|
|
65 | 48 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
66 | 49 | ]
|
67 | 50 |
|
68 |
| - |
69 | 51 | CORS_ALLOW_ALL_ORIGINS = True
|
| 52 | + |
70 | 53 | ROOT_URLCONF = 'Roadside_backend.urls'
|
71 | 54 |
|
72 | 55 | TEMPLATES = [
|
|
85 | 68 | },
|
86 | 69 | ]
|
87 | 70 |
|
88 |
| -# WSGI_APPLICATION = 'Roadside_backend.wsgi.application' |
89 |
| -ASGI_APPLICATION = "Roadside_backend.asgi.application" |
90 |
| -AUTH_USER_MODEL = "users.User" |
91 |
| - |
92 |
| -# Database |
93 |
| -# https://docs.djangoproject.com/en/5.1/ref/settings/#databases |
| 71 | +ASGI_APPLICATION = 'Roadside_backend.asgi.application' |
| 72 | +AUTH_USER_MODEL = 'users.User' |
94 | 73 |
|
95 |
| -# settings.py |
| 74 | +# Database configuration |
96 | 75 | DATABASES = {
|
97 | 76 | 'default': {
|
98 | 77 | 'ENGINE': 'django.db.backends.postgresql',
|
99 |
| - 'NAME': 'postgres', |
100 |
| - 'USER': 'postgres.ikxkxghdwtyyeuyxtdme', |
101 |
| - 'PASSWORD': 'Vipul@roadside123', |
102 |
| - 'HOST': 'aws-0-ap-south-1.pooler.supabase.com', |
103 |
| - 'PORT': '6543', |
| 78 | + 'NAME': config('DATABASE_NAME'), |
| 79 | + 'USER': config('DATABASE_USER'), |
| 80 | + 'PASSWORD': config('DATABASE_PASSWORD'), |
| 81 | + 'HOST': config('DATABASE_HOST'), |
| 82 | + 'PORT': config('DATABASE_PORT', cast=int), |
104 | 83 | }
|
105 | 84 | }
|
106 | 85 |
|
107 |
| - |
| 86 | +# Channel layers configuration |
108 | 87 | CHANNEL_LAYERS = {
|
109 | 88 | "default": {
|
110 | 89 | "BACKEND": "channels.layers.InMemoryChannelLayer",
|
111 | 90 | },
|
112 | 91 | }
|
113 | 92 |
|
114 |
| -# Password validation |
115 |
| -# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators |
| 93 | +# Redis cache configuration |
| 94 | +CACHES = { |
| 95 | + "default": { |
| 96 | + "BACKEND": "django_redis.cache.RedisCache", |
| 97 | + "LOCATION": config('REDIS_LOCATION'), |
| 98 | + "OPTIONS": { |
| 99 | + "CLIENT_CLASS": "django_redis.client.DefaultClient", |
| 100 | + }, |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +SESSION_ENGINE = "django.contrib.sessions.backends.cache" |
| 105 | +SESSION_CACHE_ALIAS = "default" |
116 | 106 |
|
| 107 | +# Password validation |
117 | 108 | AUTH_PASSWORD_VALIDATORS = [
|
118 |
| - { |
119 |
| - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
120 |
| - }, |
121 |
| - { |
122 |
| - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
123 |
| - }, |
124 |
| - { |
125 |
| - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
126 |
| - }, |
127 |
| - { |
128 |
| - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
129 |
| - }, |
| 109 | + {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, |
| 110 | + {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'}, |
| 111 | + {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'}, |
| 112 | + {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}, |
130 | 113 | ]
|
131 | 114 |
|
132 |
| - |
133 | 115 | # Internationalization
|
134 |
| -# https://docs.djangoproject.com/en/5.1/topics/i18n/ |
135 |
| - |
136 | 116 | LANGUAGE_CODE = 'en-us'
|
137 |
| - |
138 | 117 | TIME_ZONE = 'UTC'
|
139 |
| - |
140 | 118 | USE_I18N = True
|
141 |
| - |
142 | 119 | USE_TZ = True
|
143 | 120 |
|
144 |
| - |
145 |
| -# Static files (CSS, JavaScript, Images) |
146 |
| -# https://docs.djangoproject.com/en/5.1/howto/static-files/ |
147 |
| - |
| 121 | +# Static files |
148 | 122 | STATIC_URL = 'static/'
|
149 | 123 |
|
150 |
| -# Default primary key field type |
151 |
| -# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field |
152 |
| - |
153 | 124 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
154 | 125 |
|
155 |
| - |
| 126 | +# Django REST framework settings |
156 | 127 | REST_FRAMEWORK = {
|
157 |
| - 'DEFAULT_AUTHENTICATION_CLASSES': ( |
| 128 | + 'DEFAULT_AUTHENTICATION_CLASSES': ( |
158 | 129 | 'rest_framework_simplejwt.authentication.JWTAuthentication',
|
159 | 130 | ),
|
160 | 131 | 'DEFAULT_PERMISSION_CLASSES': (
|
|
166 | 137 | ),
|
167 | 138 | }
|
168 | 139 |
|
169 |
| -from datetime import timedelta |
170 |
| - |
| 140 | +# Simple JWT settings |
171 | 141 | SIMPLE_JWT = {
|
172 |
| - 'ACCESS_TOKEN_LIFETIME': timedelta(days=30), |
| 142 | + 'ACCESS_TOKEN_LIFETIME': timedelta(days=30), |
173 | 143 | 'REFRESH_TOKEN_LIFETIME': timedelta(days=40),
|
174 |
| - 'ROTATE_REFRESH_TOKENS': True, |
175 |
| - 'BLACKLIST_AFTER_ROTATION': True, |
176 |
| - |
177 |
| - 'ALGORITHM': 'HS256', |
178 |
| - 'SIGNING_KEY': SECRET_KEY, |
179 |
| - 'VERIFYING_KEY': None, |
180 |
| - |
181 |
| - 'AUTH_HEADER_TYPES': ('Bearer',), |
| 144 | + 'ROTATE_REFRESH_TOKENS': True, |
| 145 | + 'BLACKLIST_AFTER_ROTATION': True, |
| 146 | + 'ALGORITHM': 'HS256', |
| 147 | + 'SIGNING_KEY': SECRET_KEY, |
| 148 | + 'AUTH_HEADER_TYPES': ('Bearer',), |
182 | 149 | 'USER_ID_FIELD': 'id',
|
183 | 150 | 'USER_ID_CLAIM': 'user_id',
|
184 |
| - |
185 | 151 | 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
|
186 | 152 | 'TOKEN_TYPE_CLAIM': 'token_type',
|
187 |
| - |
188 | 153 | 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
|
189 |
| - 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), |
| 154 | + 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), |
190 | 155 | 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
|
191 | 156 | }
|
192 | 157 |
|
193 |
| - |
194 |
| - |
| 158 | +# App environment configuration |
| 159 | +APP_ENV = config('APP_ENV', default='dev') |
| 160 | + |
| 161 | +if APP_ENV == 'prod': |
| 162 | + DEBUG = False |
| 163 | + # Production-specific configurations |
| 164 | + STATIC_ROOT = BASE_DIR / 'staticfiles' |
| 165 | + SECURE_SSL_REDIRECT = True |
| 166 | + SESSION_COOKIE_SECURE = True |
| 167 | + CSRF_COOKIE_SECURE = True |
| 168 | + SECURE_HSTS_SECONDS = 3600 |
| 169 | + SECURE_HSTS_INCLUDE_SUBDOMAINS = True |
| 170 | + SECURE_HSTS_PRELOAD = True |
0 commit comments