我在heroku上遇到了一个奇怪的行为,我开发了一个应用程序并且完全正常运行,它使用了多个插件,例如社交身份验证,存储,django-ses。
任何方式,只要DEBUG模式打开,应用程序运行正常,一旦我将其关闭我从导入操作抱怨错误
这是堆栈,以前有人经历过这个吗?
2013-09-18T13:30:18.929630+00:00 app[web.1]: 2013-09-18 08:30:18 [7] [ERROR] Error handling request
2013-09-18T13:30:18.929630+00:00 app[web.1]: Traceback (most recent call last):
2013-09-18T13:30:18.929630+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 126, in handle_request
2013-09-18T13:30:18.929630+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2013-09-18T13:30:18.929630+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
2013-09-18T13:30:18.929630+00:00 app[web.1]: response = self.get_response(request)
2013-09-18T13:30:18.929630+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
2013-09-18T13:30:18.929630+00:00 app[web.1]: response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2013-09-18T13:30:18.929630+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 220, in handle_uncaught_exception
2013-09-18T13:30:18.930013+00:00 app[web.1]: if resolver.urlconf_module is None:
2013-09-18T13:30:18.930013+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
2013-09-18T13:30:18.930013+00:00 app[web.1]: self._urlconf_module = import_module(self.urlconf_name)
2013-09-18T13:30:18.930013+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-09-18T13:30:18.930013+00:00 app[web.1]: __import__(name)
2013-09-18T13:30:18.930013+00:00 app[web.1]: File "/app/khooosh/urls.py", line 8, in <module>
2013-09-18T13:30:18.930013+00:00 app[web.1]: admin.autodiscover()
2013-09-18T13:30:18.930013+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
2013-09-18T13:30:18.930013+00:00 app[web.1]: import_module('%s.admin' % app)
2013-09-18T13:30:18.930013+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-09-18T13:30:18.930277+00:00 app[web.1]: __import__(name)
2013-09-18T13:30:18.930277+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/social_auth/admin.py", line 19, in <module>
2013-09-18T13:30:18.930277+00:00 app[web.1]: all_names = _User._meta.get_all_field_names()
2013-09-18T13:30:18.930277+00:00 app[web.1]: AttributeError: 'str' object has no attribute '_meta'
更新settings.py
import dj_database_url
import os
import sys
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.path.pardir, os.path.pardir))
def base(f=''):
return os.path.join(BASE_DIR, f)
def app_base(f=''):
return os.path.join(base('XXXX'), f)
sys.path.insert(0, app_base())
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Mo Mughrabi', 'XXXX'),
)
MANAGERS = ADMINS
DATABASES = {'default': dj_database_url.config()}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*', ]
# 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/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en'
ADMIN_LANGUAGE_CODE = LANGUAGE_CODE
gettext = lambda s: s
LANGUAGES = (
('en', gettext('English')),
('ar', gettext('Arabic'))
)
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
# 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: "/var/www/example.com/media/"
MEDIA_ROOT = base('public_media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/public_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: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
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.
app_base('public-assets'),
)
# 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',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '+_-$@5jw*k)43blbi%ky!vlvi8dvhlotre&9eui!6&0$qnf0c^'
# 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.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'apps.rank.middleware.HitCountMiddleware',
'middleware.LocaleMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'khooosh.wsgi.application'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.request',
'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',
# custom context processors
'khooosh.context_processors.load_settings',
'constance.context_processors.config',
)
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
base('templates'),
)
# custom user model
AUTH_USER_MODEL = 'account.User'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# suit admin
'suit',
'suit_redactor',
'suit_ckeditor',
'filebrowser',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
# apps
'south',
'mptt',
'storages',
'constance.backends.database',
'social_auth',
'captcha',
'modeltranslation',
'tinymce',
'sorl.thumbnail',
'djcelery',
'django_extensions',
'haystack',
# apps custom
'apps.media',
'apps.account',
'apps.list',
'apps.bargain',
'apps.promotion',
'apps.pages',
'apps.dwh',
'apps.campaigner',
'apps.rank',
'apps.mail_list',
'apps.search'
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
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,
},
}
}
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# constance config
CONSTANCE_CONFIG = {}
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
# custom settings
TEMPLATE_PUBLIC_ASSETS = 'leisure'
# reCaptcha details
RECAPTCHA_PUBLIC_KEY = '6Leu6-QSAAAAAJPxSFBrIVDoSF9u2JF7i6LfX6Sm'
RECAPTCHA_PRIVATE_KEY = '6Leu6-QSAAAAAOAWWy9f7CUX5PIbbN0DSbLJmUFg'
# authentication backends
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.google.GoogleOAuthBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.contrib.linkedin.LinkedinBackend',
'social_auth.backends.contrib.instagram.InstagramBackend',
'django.contrib.auth.backends.ModelBackend',
'backends.EmailAuthBackend',
)
TWITTER_EXTRA_DATA = [
('screen_name', 'screen_name'),
('user_info', 'user_info')
]
FACEBOOK_EXTRA_DATA = [
('username', 'username'),
('gender', 'gender'),
('bio', 'bio'),
('last_name', 'last_name'),
('link', 'link'),
('middle_name', 'middle_name'),
('first_name', 'first_name'),
('hometown', 'hometown'),
('email', 'email'),
]
FACEBOOK_EXTENDED_PERMISSIONS = ['email', ]
# Add email to requested authorizations.
LINKEDIN_SCOPE = ['r_basicprofile', 'r_emailaddress', 'r_fullprofile']
# Add the fields so they will be requested from linkedin.
LINKEDIN_EXTRA_FIELD_SELECTORS = ['email-address', 'headline', 'industry', 'public-profile-url',
'interests', 'date-of-birth', 'positions', 'picture-url']
# Arrange to add the fields to UserSocialAuth.extra_data
LINKEDIN_EXTRA_DATA = [
('id', 'id'),
('first-name', 'first_name'),
('last-name', 'last_name'),
('email-address', 'email_address'),
('headline', 'headline'),
('industry', 'industry'),
('public-profile-url', 'public_url'),
('interests', 'interests'),
('date-of-birth', 'date_of_birth'),
('positions', 'positions'),
('picture-url', 'picture_url'),
]
SOCIAL_AUTH_PIPELINE = (
'apps.account.pipeline.social_auth_user', # to handle is_active = False as suspended user
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.misc.save_status_to_session',
'apps.account.pipeline.redirect_to_form',
'apps.account.pipeline.set_username',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'apps.account.pipeline.update_email_validity',
'apps.account.pipeline.set_user_details',
'apps.account.pipeline.social_extra_data',
'apps.account.pipeline.destroy_session_data',
)
SOCIAL_AUTH_PARTIAL_PIPELINE_KEY = 'partial_pipeline'
# for django-orm-extensions to not conflict with south
SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
# Amazon SES settings
# Email Configuration using Amazon SES Services
EMAIL_BACKEND = 'django_ses.SESBackend'
# These are optional -- if they're set as environment variables they won't
# need to be set here as well
AWS_SES_ACCESS_KEY_ID = 'XXX'
AWS_SES_SECRET_ACCESS_KEY = 'XXX'
# Additionally, you can specify an optional region, like so:
AWS_SES_REGION_NAME = 'us-east-1'
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
def get_cache():
try:
os.environ['MEMCACHE_SERVERS'] = os.environ['MEMCACHIER_SERVERS'].replace(',', ';')
os.environ['MEMCACHE_USERNAME'] = os.environ['MEMCACHIER_USERNAME']
os.environ['MEMCACHE_PASSWORD'] = os.environ['MEMCACHIER_PASSWORD']
return {
'default': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'TIMEOUT': 500,
'BINARY': True,
'OPTIONS': {'tcp_nodelay': True}
}
}
except:
return {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/tmp/django_kh_cache',
}
}
CACHES = get_cache()
# suit-django config
SUIT_CONFIG = {
'ADMIN_NAME': 'Khooosh admin',
# Set to empty string if you want to hide search from menu
'CONFIRM_UNSAVED_CHANGES': False,
'SEARCH_URL': '',
'MENU_ICONS': {
'sites': 'icon-leaf',
'account': 'icon-user',
'list': 'icon-th-list',
'media': 'icon-file',
'pages': 'icon-pencil',
}
}
FILEBROWSER_SUIT_TEMPLATE = True
#locale path
# locale paths
LOCALE_PATHS = (
base('locale'),
)
# mailchip API key
MAILCHIMP_API_KEY = 'XXXX'
MAILCHIMP_LIST_KEY = 'XXXXX'
# track hitcount app
RANK_HITCOUNT_TRACK = {
'bargain-detail': {'app_label': 'bargain', 'model': 'Bargain', 'pk_view_variable': 'pk'},
'promotion-detail': {'app_label': 'promotion', 'model': 'Promotion', 'pk_view_variable': 'pk'},
}
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
try:
from local_env import *
except ImportError:
pass
try:
if os.environ['SETTING_FILE'] in ('staging', 'local_env', 'production'):
exec('from khooosh.settings.%s import *' % os.environ['SETTING_FILE'])
except KeyError:
pass
# tinymce setup - it should be after importing
# external settings, as this part uses STATIC_URL to determine location
TINYMCE_JS_URL = os.path.join(STATIC_URL, TEMPLATE_PUBLIC_ASSETS, 'vendors/tinymce/tinymce.min.js')
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,spellchecker,paste,searchreplace",
'theme': "modern",
'cleanup_on_startup': True,
'custom_undo_redo_levels': 10,
}
CELERY_RESULT_BACKEND = "database"
STATIC_URL_THEME = '{0}{1}/'.format(STATIC_URL, TEMPLATE_PUBLIC_ASSETS)
答案 0 :(得分:0)
登录 Django 1.10.3 管理面板时,我遇到了类似的错误: AttributeError:'str'对象没有属性'pk'。我正在使用自己的上下文处理器(就像你一样),它似乎导致了问题。尝试将settings.c中的 context_processor 列表中的上下文处理器移至顶部。它对我有帮助。