i have removed everything brother database and all the project and recreated all things with the same code forgive me on latency for reading, cause i was trying to see if anything in the project is causing this
and i have installed postgresql 15 with 14 and both works fine in pgadmin but i can’t run except one of them on the localhost
so the database has no relation
i know that you told me to not think ever to delete the database but i have no data already on it
this is my first project to deploy and it’s my profile
so i was keeping the same code that already works before
so the problem is in .env and settings
after i recreate the project
the same thing happens as i didn’t change anything
even admin page i can’t get it the same thing happens on any url not only home
i have created new super user and it has been created successfully and no errors but still cant see anything in browser
so here is the all settings and .env file
setings.py
from pathlib import Path
import os
from django.core.management.utils import get_random_secret_key
import psycopg2
import sys
import dj_database_url
from dotenv import load_dotenv
load_dotenv()
INSTALLED_APPS = [ # pip install django-phonenumber-field[phonenumbers
'rest_framework',
'account.apps.AccountConfig',
'django.contrib.admin',
"daphne",
'django.contrib.auth', # Core authentication framework and its default models
'django.contrib.contenttypes', # Django content type system (allows permissions to be associated with models).
'django.contrib.sessions',
'django.contrib.sites', # set of a single Django application/codebase with different sites (that can use different databases, logic in views, etc)
'django.contrib.messages',
'django.contrib.staticfiles',
'phonenumber_field', # pip install django-phonenumber-field[phonenumberslite]
'crispy_forms',
"mailer",
#'django_registration',
'django_filters',
# CORS
'corsheaders',
'bootstrap4',
"django_bootstrap5",
'chat',
'blog.apps.BlogConfig',
'home.apps.HomeConfig',
'contact.apps.ContactConfig',
'job.apps.JobConfig',
'postman.apps.PostmanConfig', # either this or post man not both
'ajax_select',
'pinax.notifications',
#"messages", # it will clashes with postman.Message, so don't activate both, but just one and postman is the best ever
'django_private_chat2.apps.DjangoPrivateChat2Config',
'debug_toolbar', # after install pip3 install django-debug-toolbar
]
SITE_ID=1
AUTH_USER_MODEL = 'account.User' # because we have extended user Model using a custome model in user app
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window
MIDDLEWARE = [
# CORS
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', # Manages sessions across requests
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware', # after pip3 install django-debug-toolbar
'django.contrib.auth.middleware.AuthenticationMiddleware', # Associates users with requests using sessions.
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'http://localhost:8080',
)
#CACHE_MIDDLEWARE_ALIAS = '' # The cache alias to use for storage
CACHE_MIDDLEWARE_SECONDS = 600 # The number of seconds each page should be cached
CSRF_COOKIE_AGE = 31449600
CACHE_MIDDLEWARE_KEY_PREFIX = ''
CRISPY_TEMPLATE_PACK = 'bootstrap4'
ROOT_URLCONF = 'project.urls'
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
#BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
'LOCATION': ['127.0.0.1:11211', '0.0.0.0:11211'],
'TIMEOUT': 200,
'OPTIONS': {
'no_delay': True,
'ignore_exc': True,
'max_pool_size': 4,
'use_pooling': True,
}
},
'redis': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': ['redis://127.0.0.1:6379', os.getenv("REDIS_URL"),],
'OPTIONS': {
'db': '10',
'parser_class': 'redis.connection.PythonParser',
'pool_class': 'redis.BlockingConnectionPool',
}
},
'dummy': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
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',
#"messages.context_processors.user_messages", # i would use postman
],
},
},
]
WSGI_APPLICATION = 'project.wsgi.application'
CSRF_COOKIE_SECURE = True
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
EMAIL_BACKEND = "mailer.backend.DbBackend"
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Postman Settings
POSTMAN_I18N_URLS = True # True, if you want the internationalization of URL patterns, Defaults to: False
POSTMAN_DISALLOW_ANONYMOUS = True # True if you do not allow visitors to write to users, default is False
POSTMAN_DISALLOW_MULTIRECIPIENTS = False # True if you do not allow more than one username in the recipient field, default is False.
POSTMAN_DISALLOW_COPIES_ON_REPLY = False # True if you do not allow additional recipients when replying, default is False.
POSTMAN_DISABLE_USER_EMAILING = False # True if you do not want basic email notification to users.
POSTMAN_NOTIFICATION_APPROVAL = 'account.views.notification_approval'
def get_from_email(context):
return '<{} admin> no-reply@domain.tld'.format(context['action'])
POSTMAN_FROM_EMAIL = 'from@host.tld' # get_from_email, default is DEFAULT_FROM_EMAIL
def get_params_email(context):
return {
'reply_to': ['someone@domain.tld'],
'headers': {'X-my-choice': 'my-value'}
} if context['action'] == 'acceptance' else {}
POSTMAN_PARAMS_EMAIL = get_params_email # default is None
POSTMAN_AUTO_MODERATE_AS = True # default is None
POSTMAN_SHOW_USER_AS = 'get_full_name' # lambda u: u.get_profile().nickname. like => progile.get_absolute_url()
POSTMAN_NAME_USER_AS = 'last_name'
POSTMAN_QUICKREPLY_QUOTE_BODY = True
POSTMAN_NOTIFIER_APP = 'pinax_notifications'
POSTMAN_MAILER_APP = 'mailer'
POSTMAN_AUTOCOMPLETER_APP = {'name': 'ajax_select', 'field': 'AutoCompleteField', 'arg_name': 'channel', 'arg_default': {}}
SECRET_KEY = os.getenv("SECRET_KEY", get_random_secret_key()) # get_random_secret_key() supplied as default value
DEBUG = True
ALLOWED_HOSTS = ['nagies.digitalocean.com', 'localhost', '127.0.0.1'] # ALLOWED_HOSTS = ['*']
from django.core.exceptions import ImproperlyConfigured
def get_env_value(env_variable):
try:
return os.environ[env_variable]
except KeyError:
error_msg = 'Set the {} environment variable'.format(env_variable)
raise ImproperlyConfigured(error_msg)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # django.db.backends.mysql'
'NAME': os.environ.get('PG_NAME'), # DB Name os.environ['PG_NAME'],
'USER': os.environ.get('PG_USER'), # os.environ['PG_USER'], from server register => connection tab change the name of server and username
'PASSWORD': os.getenv('PG_PASSWORD'), # os.environ['PG_PASSWORD'],
'HOST': os.environ.get('PG_HOST'), # os.environ['PG_HOST'],
'PORT': os.environ.get('PG_PORT'), # int(os.environ['PG_PORT']),
}
}
ENVIRONMENT = os.getenv('ENVIRONMENT', 'development') # development is the default valuew
if ENVIRONMENT == 'production':
DEBUG = True
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", get_random_secret_key())
SESSION_COOKIE_SECURE = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_SECONDS = 60 # 31536000
SECURE_REDIRECT_EXEMPT = []
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..')
SITE_ROOT = PROJECT_ROOT / BASE_DIR # SITE_ROOT = BASE_DIR
TEMPLATE_DIRS = (
os.path.join(SITE_ROOT, 'templates'),
)
STATIC_URL = '/static/' # then you can reach to all static from this url
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # for production use "/var/www/example.com/static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIAFILES_DIRS = (BASE_DIR / 'media')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
ASGI_APPLICATION = "project.asgi.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
}, # you can add more channel layers here
}
.env
DJANGO_DEBUG=True
DEVELOPMENT_MODE=True
ENVIRONMENT=development
# production database
DB_NAME=db_name
DB_USERNAME=username
DB_PASSWORD=password
DB_URL=url...
DB_PORT=5342
# dev databse
PG_NAME=name
PG_USER=username
PG_PASSWORD=pasword
PG_HOST=localhost
PG_PORT=5432
SECRET_KEY='django-insecure-...'
DJANGO_ALLOWED_HOSTS=nagy.digitalocean.com,127.0.0.1,localhost
REDIS_URL=redis://...
DISABLE_COLLECTSTATIC = 1
please brother help me i am really disparate