How exactly configure Django to send emails with bug reports? - django

I am really novice with Django, and I am having troubles in configuring my app to send me emails with the bug reports.
I already set on the settings file the required variables as I saw on the Django documentation, like this:
DEBUG = False
...
ADMINS = [('myname', 'myemail#server')] # For server errors
MANAGERS = [('myname', 'myemail#server')] # For missing pages errors
I provoked a error for testing, but nothing happened, no email. What should I do?
This is the code of the settings file (without sensitive data, of course):
"""
Django settings for genform project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '****************************************'
DEBUG = False
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'widget_tweaks',
'generador',
'menu',
'parametros_transformados',
'seguridad',
'tablas_de_no_parametros',
'reportes',
'logger',
'parametros',
'django_openid_auth'
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
AUTHENTICATION_BACKENDS = (
'django_openid_auth.auth.OpenIDBackend',
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATES = [
{
'BACKEND':'django.template.backends.django.DjangoTemplates',
'DIRS':[os.path.join(os.path.dirname(__file__), '../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',
],
},
},
]
OPENID_UPDATE_DETAILS_FROM_SREG = True
ROOT_URLCONF = 'genform.urls'
WSGI_APPLICATION = 'genform.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '*****',
'USER': '******',
'PASSWORD': '******',
'HOST': '***********',
'PORT': '***',
}
}
STATICFILES_DIRS = (
#os.path.dirname(__file__)+"static",
# Put strings here, like "/home/html/site_media" or "C:/www/django/site_media".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(os.path.dirname(__file__), '../static'),
)
AUTH_PROFILE_MODULE = 'seguridad.c_perfil_usuario'
LOGIN_REDIRECT_URL = '/index'
OPENID_SSO_SERVER_URL = '***********'
OPENID_CREATE_USERS = True
LANGUAGE_CODE = 'es-es'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
ADMINS = [('MyName', 'myemail#server')]
MANAGERS = [('MyName', 'myemail#server')]

What's your LOGGING configuration?
I use the following in my production environment:
ADMINS = [
('Admin1', 'admin1#mail.com'),
('Admin2', 'admin2#mail.com')
]
MANAGERS = ADMINS
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # for testing
EMAIL_HOST = 'relay.server.com'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false', ],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins', ],
'level': 'ERROR',
'propagate': True
},
'django.security.DisallowedHost': {
'level': 'ERROR',
'handlers': ['console', 'mail_admins', ],
'propagate': True
}
}
}
Make sure you have a valid EMAIL_BACKEND defined. You can use a service like mailgun or even gmail if you don't have a own SMTP server (EMAIL_HOST).

Thoese settings look correct, but there are other things that may be holding you up.
Email info in settings.py may not be configured
You have overwritten the default log settings in settings.py and are not writing errors to the email log.
If one or both of these are not setup correctly, then you won't get the emails.
To fix 1 you can look at this answer: https://stackoverflow.com/a/4642194/4788717
To fix 2, you can check out the docs: https://docs.djangoproject.com/en/dev/topics/logging/ and make sure you have either the default or mail admins case:
LOGGING = {
...
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'filters': ['special']
...
}

Related

"GET / HTTP/1.1" 500 145

Anytime I turn debug to false in my settings.py my site gives a server error. This is what my server shows and the site doesn't work again but when debug is true it works perfectly, I don't know what's wrong anyone with ideas on what might be going wrong
Performing system checks...
System check identified no issues (0 silenced).
October 21, 2022 - 23:47:07
Django version 4.1.2, using settings 'dlcfogbomoso.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[21/Oct/2022 23:47:09] "GET / HTTP/1.1" 500 145
[21/Oct/2022 23:54:18] "GET / HTTP/1.1" 500 145
This is my settings.py file check it out for any error(s):
from pathlib import Path
import os
from decouple import config
from django.core.management.utils import get_random_secret_key
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent. Parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "Django-insecure-)=l1an%f&lb0+7z#!5l!ang_l!76ahs4eb-$((lt7vo1-mv0(*"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
"myapp",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "dlcfogbomoso.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [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",
],
},
},
]
WSGI_APPLICATION = "dlcfogbomoso.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "dlcfogbomoso",
"USER": "postgres",
"PASSWORD": "admin",
"HOST": "localhost"
}
}
# Password validation
# https://docs.djangoproject.com/en/4.1/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",
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = "/static/"
MEDIA_ROOT = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Please what am I doing wrong?
Not a definitive answer, but help. too long for comment
Go into your settings.py and add the code block below. This overrides the default Logging settings to output errors to the console even when debug is set as False. If you already have a LOGGING dict in the settings, just comment it out
Note: defaults are commented out, I just disabled the filters & disabled the existing default loggers
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
# 'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'formatters': {
'django.server': {
'()': 'django.utils.log.ServerFormatter',
'format': '[{server_time}] {message}',
'style': '{',
}
},
'handlers': {
'console': {
'level': 'INFO',
#'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
},
'django.server': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'django.server',
},
'mail_admins': {
'level': 'ERROR',
#'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django': {
'handlers': ['console', 'mail_admins'],
'level': 'INFO',
},
'django.server': {
'handlers': ['django.server'],
'level': 'INFO',
'propagate': False,
},
}
}

Django/Heroku deployment problems: Won't work on Debug = False

I got my app to deploy, but pages that require an id in session are not rendering. When I set debug = true, everything works fine. Otherwise, I get error 500 message. I've tried many different solutions to no avail.
I imagine the problem is somewhere in my settings.py so I have included that below. I was also able to log the startup so that is included as well.
The main page and pages that don't get a request.session passed into them work fine, as well as functions that update the database. Only pages that require an id passed into the path are not working.
update:
I ran the logentries extension for heroku and found an error on this line:
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
ValueError: Missing staticfiles manifest entry for '/css/bootstrap.min.css'
I still don't know what to do
import dj_database_url
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', '.herokuapp.com']
# Application definition
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'wiki_app',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
]
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'coding_dojo_final_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'coding_dojo_final_project.wsgi.application'
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '***',
'HOST': 'localhost',
'PORT': '****',
}
}
WHITENOISE_USE_FINDERS = True
...
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ('%(asctime)s [%(process)d] [%(levelname)s] '
'pathname=%(pathname)s lineno=%(lineno)s '
'funcname=%(funcName)s %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}
}
STATIC_URL = '/static/'
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
not exactly sure, but something went wrong when I compiled all my static filed. I had to...
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
- STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

Css and Javascripts not loading on login page in Django?

Here is my settings file.. I am getting the login page but the css and javascripts are not loading.
I gotthe whole project and i have to start working on it but i only know the basic of django so not sure why css and javascripts arenot loading. this is a very old project so it is using python 2.6.5 and django 1.3. the folder structure is also old.
# Django settings for athena.
import socket
# determine whether it's prod or dev or test/uat
if socket.gethostname().split('.')[0].lower().strip() in ('athena-dev', 'athena-test', 'lucid32'):
ATHENA_PROD_MODE = False
elif socket.gethostname().split('.')[0].lower().strip() == 'athena':
ATHENA_PROD_MODE = True
else:
raise Exception('cannot determine what mode (prod or dev) to operate in')
ATHENA_UAT_MODE = (socket.gethostname().split('.')[0].lower().strip() == 'athena-test')
if ATHENA_PROD_MODE:
DEBUG = False
else:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (('PASystemSupport', 'pasystemsupport#apa.org'), )
MANAGERS = ADMINS
if ATHENA_PROD_MODE:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'Athena',
'USER': 'ftdbuser',
'PASSWORD': 'f0lt5xt',
'HOST': 'PIDB-SQL',
'OPTIONS': {
'driver': 'SQL Server',
'autocommit': True,
'dsn': 'PIDB-SQL',
'use_mars': True
}
}
}
elif ATHENA_UAT_MODE:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'Athena-UAT',
'USER': 'ftdbuser',
'PASSWORD': 'f0lt5xt',
'HOST': 'LANDB-DEV',
'OPTIONS': {
'driver': 'SQL Server',
'autocommit': True,
'dsn': 'LANDB-DEV',
'use_mars': True
}
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/vagrant/Athena/athena_root/athena.db',
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/New_York'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/vagrant/Athena/athena_root/athena_static/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/athena_static/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '7*f!l)^v!81vog#yzd23scp5+30db=)bub(j88nz!37nnt62mh'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'athena_root.athena.middleware.ApplyAuthentication',
'athena_root.athena.workflow.middleware.ProdViewPermissions'
)
ROOT_URLCONF = 'athena_root.athena.urls'
TEMPLATE_DIRS = ('/vagrant/Athena/athena_root/athena_templates',
'/vagrant/Athena/athena_root/ltt/templates',
'/vagrant/Athena/athena_root/errata/templates')
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"athena_root.athena.template_context_proc.baseTemplateContext"
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.humanize',
'athena_root.athena',
'athena_root.ltt',
'athena_root.errata'
)
EMAIL_HOST = 'mailhost.apa.org'
SERVER_EMAIL = 'PASystemsupport#apa.org'
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True
},
'aem_db_logger': {
'level': 'DEBUG',
'class': 'athena_root.errata.log.DatabaseLoggingHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django': {
'handlers': ['null'],
'propagate': True,
'level': 'INFO',
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': False,
},
'athena_root.errata': {
'handlers': ['aem_db_logger'],
'level': 'DEBUG',
'propagate': True
}
}
}
AUTHENTICATION_BACKENDS = ('athena_root.athena.auth.backends.AthenaAuthBackend',)
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
SESSION_COOKIE_AGE = 7257600
SESSION_SAVE_EVERY_REQUEST = False
`

Dajaxice running locally, but django settings problems to make it work online

I have created a Django account which uses Dajaxice and Dajax.
I run my website in an azure VM. When I run it with localhost Dajaxice/Dajax work perfectly.
However, online this does not work anymore. I have some configurations problems in my settings, but I am unable to fix it.
Locally, Dajaxice/Dajax is pointed in this way:
<script src="/static/dajaxice/dajaxice.core.js" type="text/javascript" charset="utf-8"></script>
The Dajaxice/Dajax function is called like this:
GET http://localhost:1465/dajaxice/chocolate.chocolate.cellphone/?argv=%7B%22cell%22%3A%22jk%22%2C%22pID%22%3A%228353%22%7D
How should I change my settings, so I can access dajaxice online?
This is my settings.py so far:
from os import path
PROJECT_ROOT = path.dirname(path.abspath(path.dirname(__file__)))
LOGIN_REDIRECT_URL = ''
HTMLFILES_DIR = 'C:\inetpub\wwwroot\chocolate\chocolate\chocolate\htmlFiles'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('x', 'x#gmail.com'),
)
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'NAME': 'xx',
'ENGINE': 'x',
'HOST': 'x.x.x',
'USER': 'x#zx',
'PASSWORD': 'x!',
'OPTIONS': {
'provider': 'x'
}
}
}
TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = HTMLFILES_DIR + '\Pictures'
MEDIA_URL = 'http://localhost:1781/Pictures/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'dajaxice.finders.DajaxiceFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'xxxxxxxxxxxxxxxxxx'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'chocolate.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'chocolate.wsgi.application'
TEMPLATE_DIRS = (
HTMLFILES_DIR
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'chocolate.chocolate',
'dajaxice',
'dajax',
# Uncomment the next line to enable the admin:
'django.contrib.admin'
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'x#outlook.com'
EMAIL_HOST_PASSWORD = 'x'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'dajaxice':{
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
}
}
Well, I found how to do it. For anyone with few experience in Django, this information could be helpful.
When I use localhost, having the following information is just fine:
STATIC_ROOT = ''
STATIC_URL = '/static/'
However, once you plan to deploy your application, you need to create a file somewhere in your application and include the path in STATIC_ROOT. In my case, it was the following:
STATIC_ROOT = 'C:/inetpub/wwwroot/chocolate/chocolate/chocolate/static/'
I manually created the file called static, which you can see above. Then, add the name of the file created in STATIC_URL.
STATIC_URL = '/static/'
Afterwards, with your console access the file where you have your app's manage.py . Make sure to have added python as a command and write python manage.py collectstatic . All your static files will located there, in the static file you created. In my case, the files of dajaxice and dajax appeared in this folder after having written python manage.py collectstatic.
Now, dajaxice/dajax should work online after deployment.

How to solve ORA-12505 without SID

I'm working on a django project, and when trying to connect to an Oracle database I get this message:
DataBaseError: ORA-12505: TNS:listener does not currently know of SID given in
connect descriptor
All the answers online have said "You need to make sure you have the correct SID", so I asked the person at my work who manages all the databases and he said "We don't have SID's for these guys. We use service names instead."
I can access the db via the command line, but trying to get django to do this is driving me crazy. Any help would be greatly appreciated. Thanks
EDIT: Here is my settings.py file. It's not too interesting... this is a fresh project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = ( ,
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'a_host',
'PORT': '1521',
}
}
TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'sandbox.urls'
WSGI_APPLICATION = 'sandbox.wsgi.application'
TEMPLATE_DIRS = (
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
If you have DBA access, you can get the SID with:
select instance from V$THREAD;
Typically, it's the same name used in your TNSNAMES.ORA file (MYDB in the below case).
MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver.mynetwork)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = MYDB.mynetwork)
)
)
So the settings would be:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'MYDB',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbserver.mynetwork',
'PORT': '1521',
}
}
For anyone else that might face a similar issue here is another way that worked for me....if you just have the Service name and not the SID then use the following steps to setup your Django settings:
1. Get the instance name using following SQL
select sys_context('userenv','instance_name') from dual; --=><Myinstance>
Replace that in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '<Myinstance>',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbserver.mynetwork',
'PORT': '1521',
}
}
If you're not a DBA or don't have access to the SID for some reason, but you have access to a tsnames.ora file, then you can set up the 'NAME' key in the database set up by using the value on the left side of the equals operator. For example, if you had this entry in the tsnames.ora file:
DATABASE1 =
(DESCRIPTION = ...
)
... your DATABASES variable in settings.py would be set up with 'DATABASE1' being the value of the 'NAME' key (host and port will be blank, since those are referenced by the DATABASE1 entry in your tsnames.ora file).
This, of course, assumes that you have your environment variables (ORACLE_HOME, particularly) established so that the system can access these when referencing this variable.