A server error occurred. Please contact the administrator - python

I am developing a web-app in Django (python). It was working fine in last few days, but then i started developing another app using django. Now after switching to that old app development when I am running the server, I am getting an error: "A server error occurred. Please contact the administrator."
The traceback from the terminal:
File "/Users/somdipdey/anaconda/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
return self.application(environ, start_response)
File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
self.load_middleware()
File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
mw_class = import_string(middleware_path)
File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/Users/somdipdey/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named security
Settings file:
"""
Django settings for SteanneWebsite project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^ay$t!hm-4fm4!)ppxoc!$j1^p1b&kiv+*s&3eox^k*bh$er^8'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'News',
'Messages',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.admin',
)
ROOT_URLCONF = 'SteanneWebsite.urls'
WSGI_APPLICATION = 'SteanneWebsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
STATIC_URL = '/static/'
#Template Location
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "templates"),
)

The SecurityMiddleware is new in the Django development version, and is not available in the released 1.7. If you really want to use it, you should switch to development head, but I do not recommend running a production site from dev. You should probably just remove the reference to it in the middleware settings.

Related

Strange error Django 1.9 "runserver" command not working in one of my virtualenvs

I started having problems recently with one of my apps. It started after running command "runserver" a few times but now It doesn't start at all.
wsgi.py
"""
WSGI config for iesc project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SIAV.settings")
application = get_wsgi_application()
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SIAV.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
settings.py
# Django settings for SIAV project.
import os
import django
from datetime import timedelta
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
CRISPY_TEMPLATE_PACK = 'bootstrap3'
#def show_toolbar(request):
# return True
#SHOW_TOOLBAR_CALLBACK = show_toolbar
#INTERNAL_IPS = ('127.0.0.1',)
#DEBUG_TOOLBAR_PATCH_SETTINGS = False
ALLOWED_HOSTS = ['*']
DEBUG = True
THUMBNAIL_DEBUG = True
THUMBNAIL_PREFIX ='cache/'
DEFAULT_CHARSET = 'utf-8'
FILE_CHARSET = 'utf-8'
include_resource_uri = False
ADMINS = (
('Gustavo', 'gustavo#alluxi.mx'),
)
file_path = ('/var/www/ghost/content/data/ghost.db')
if not os.path.exists(file_path):
file_path = 'ghost.db'
MANAGERS = ADMINS
DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.db.backends.mysql',
#'ENGINE': 'tenant_schemas.postgresql_backend',
'NAME': 'siavdb', # Or path to database file if using sqlite3.
'USER': 'user', # Not used with sqlite3.
'PASSWORD': 'XXX', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',
'OPTIONS': {
'init_command': 'SET sql_mode = ""',
},
},
'sqlite': {
'NAME': file_path,
'ENGINE': 'django.db.backends.sqlite3',
'USER': '',
'PASSWORD': ''
}
}
'''
DATABASE_ROUTERS = (
'tenant_schemas.routers.TenantSyncRouter',
)
'''
LANGUAGE_SESSION_KEY = 'es'
ROOT_URLCONF = '/'
# URL of the login page.
LOGIN_URL = '/accounts/login/'
# URL of the logout page.
LOGOUT_URL = '/logout/'
# URL to redirect after login
LOGIN_REDIRECT_URL = '/SIAV/captura/'
# 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.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Monterrey'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'es'
gettext = lambda x: x
LANGUAGES = (
('es', gettext('Spanish')),
)
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
USE_THOUSAND_SEPARATOR = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = False
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = 'C:/inetpub/wwwroot/static/'
STATIC_ROOT = "/Users/gustavo/SIAV/app/static_prod"
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
#STATIC_URL = 'http://alluxi:8000/'
#STATIC_URL = 'http://localhost:100/'
# Url para desarrollo
STATIC_URL = '/static/'
# Additional locations of static files
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.
#'C:/inetpub/wwwroot/app/static'
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'dajaxice.finders.DajaxiceFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = ''
MIDDLEWARE_CLASSES = (
'django_hosts.middleware.HostsRequestMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django_hosts.middleware.HostsResponseMiddleware'
#'tenant_schemas.middleware.TenantMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
#'django_pdb.middleware.PdbMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'SIAV.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SETTINGS_PATH, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'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',
'app.views.processors.get_all_users',
'app.views.processors.get_chat_messages',
'app.views.processors.cantidades_en_proceso',
],
},
},
]
ROOT_HOSTCONF = 'hosts'
DEFAULT_HOST = 'website'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'SIAV.wsgi.application'
INSTALLED_APPS = (
# The Django sites framework is required
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'allauth',
'allauth.account',
'allauth.socialaccount',
'sorl.thumbnail',
'tastypie',
'dal',
'dal_select2',
'endless_pagination',
'bootstrap3',
'app',
'contabilidad',
'calendario',
'websock',
'crispy_forms',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
Here's the traceback:
(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$ python manage.py runserver
Performing system checks...
sh: /Users/gustavo/.virtualenvs/SIAV/bin/scriptspip.exe: No such file or directory
/Users/gustavo/.virtualenvs/SIAV/bin/python: can't open file 'manage.py': [Errno 2] No such file or directory
/Users/gustavo/.virtualenvs/SIAV/bin/python: can't open file 'manage.py': [Errno 2] No such file or directory
System check identified no issues (0 silenced).
March 09, 2016 - 17:12:52
Django version 1.9.4, using settings 'SIAV.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 54, in execute
super(Command, self).execute(*args, **options)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 93, in handle
self.run(**options)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.main(self.inner_run, None, options)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 333, in main
reloader(wrapped_main_func, args, kwargs)
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 299, in python_reloader
reloader_thread()
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 275, in reloader_thread
change = fn()
File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 205, in code_changed
stat = os.stat(filename)
OSError: [Errno 2] No such file or directory: 'manage.py'
(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$
Which python
(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$ which python
/Users/gustavo/.virtualenvs/SIAV/bin/python
I have not idea what could be wrong.
Edit:
I've already tried:
Recreating manage.py file from scratch.
Reinstalling django with pip.
Recreating the virtualenv.
The error disappears when removing this line :
url(r'^admin/', include(admin.site.urls)),
From my urls.py , however this is not a solution since a require to use the admin on my app.
Edit
This behavior seems to happen only when using django 1.9 , django 1.8 works flawlessly. I assume the error could be related to a failing third party app.

AttributeError: 'module' object has no attribute 'META' in Django Project

I am working on a blog in Python-Django. When I run the command "python manage.py runserver" in my project folder, I get following error:
Traceback (most recent call last):
File "manage.py", line 6, in <module>
server = request.META.get('wsgi.file_wrapper', None)
AttributeError: 'module' object has no attribute 'META'
I have not seen this error anywhere. Should I include Meta class in my installed_apps? How do I do it?
Here is my manage.py:
#!/usr/bin/env python
import os
import sys
from django.http import request
server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print('inside dev')
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj1.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
and settings.py:
"""
Django settings for dj1 project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(l8*%h2ids25q=x9qb7%x+(b=$1mm&yg8b5ga^0u2w9*+k%+9-'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'dj1.urls'
WSGI_APPLICATION = 'dj1.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
This is really a big code bulder.
This piece of code here makes no sense inside the manage.py
from django.http import request
server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print('inside dev')
Perhaps you copied it from somewhere, and didn't put it where it belongs.
This piece of coude would belong in a view. It will never work inside manage.py, and makes asolutely no sense there.
[EDIT]
ALSO, in a view, you should NOT include the import, or you'll get the same error. That means, don't include this from django.http import request

Django VariableDoesNotExist exception on Eclipse PyDev when rendering template

I just started a new Django project. At the moment I haven't written any code, just some tweaks on the settings file. I am using eclipse with PyDev and when I debug the app with eclipse, whenever I try to access to http://localhost:8000/admin the debugger catches a VariableDoesNotExist exception. If I resume the debugger, the page loads properly.
I've tried running ./manage.py runserver, and then the page loads fine. It is also working on heroku.
This is a screenshot from Eclipse at the moment that the debugger stops:
I've been using Eclipse with pyDev for other Django projects and never had this problem before.
This is how my settings/base.py looks like:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'knb9js8(zm#1iu4&m64n249d+i7rk%%1(atevdp&c9fx4u)72*'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages')
ROOT_URLCONF = 'pictures.urls'
WSGI_APPLICATION = 'pictures.wsgi.application'
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
I've also tried with the default value for TEMPLATE_CONTEXT_PROCESSORS.
Thank you.
How I fix it:
On the caught Exception view, right-click on the exception and then 'Ignore ...'
On PyDev > Manage Exception Breakpoints uncheck Suspend on django template render exception and make sure you don't have any of the checkboxes on the list selected.
Probably only 2 is needed, but this is what I did.

Django AUTHENTICATION_BACKENDS import error

What is the proper way to import a custom backend in settings.py? I currently have the following in settings.py:
AUTHENTICATION_BACKENDS = ('apps.apployment_site.auth.CustomAuth')
where apployment_site is the app, auth is file name, and CustomAuth is the class name.
In my view, I get: ImportError: a doesn't look like a module path after I run the following code:
from django.contrib.auth import authenticate
from apployment_site import *
authenticate(username="username", password="password")
Here's my full settings.py:
"""Django settings for apployment project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3(a=jr=tfedkqzv3f=495%0$ygxjt332(=n0&h=e2bzh(i#r*j'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apployment_site'
)
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.middleware.clickjacking.XFrameOptionsMiddleware',
)
AUTHENTICATION_BACKENDS = ('apps.apployment_site.auth.CustomAuth')
ROOT_URLCONF = 'apployment.urls'
WSGI_APPLICATION = 'apployment.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
STATIC_URL = '/static/'
make sure it's a tuple:
AUTHENTICATION_BACKENDS = ('apps.apployment_site.auth.CustomAuth',)
note the comma at the end
I don't think you need to actually import it into your view. According to the documentation, Django will go through all your authentication backends when you call authenticate().
Thus, just make sure you have all the authentication backends you want in your settings.py.

Static files in django 1.5 - working locally, not working on Heroku

I have a project in Django 1.5 and hosts it on Heroku.
The problem is that I do not see the server static files (CSS, JS) (on the user and administrator) - went through the tutorial available at: https://devcenter.heroku.com/articles/django-assets
but nothing helps.
When I start the application locally using python manage.py runserver - everything works. Below is the code from the file setting.py
import dj_database_url
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
)
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.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'blog_project.urls'
WSGI_APPLICATION = 'blog_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {'default': dj_database_url.config()}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
I think you need to change your setting for Heroku so that you include
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = (
os.path.join(PROJECT_PATH, 'static'),
)
Its using a different lookup to
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

Categories