Heroku和Django随机崩溃 [英] Heroku and Django random crashes
问题描述
有时,当我推到英雄时,我会收到一条消息:
应用程序错误
应用程序和您的页面无法提供。请稍后重试。
如果您是应用程序所有者,请查看日志以了解详细信息。
然后运行命令
$ heroku restart
几次,其突然工作正常。
来自heroku日志的错误消息很长,以下是底部的代码段:
2013-08-25T03:30:26.824149 + 00:00 app [web.1]:self._setup(name)
/ pre>
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:文件/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py,第132行,__init__
2013-08-25T03 :30:26.824453 + 00:00 app [web.1]:mod = importlib.import_module(self.SETTINGS_MODULE)
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:文件/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py,第35行,import_module
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:self._wrapped =设置(settings_module)
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:__import __(name)
2013-08 -25T03:30:26.824453 + 0 0:00 app [web.1]:文件/app/zinnia/settings.py,第5行,< module>
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:('http://django-blog-zinnia.com/xmlrpc/',))
2013- 08-25T03:30:26.824453 + 00:00 app [web.1]:文件/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py,第53行,在__getattr__
2013-08-25T03:30:26.824453 + 00:00 app [web.1]:self._setup(name)
2013-08-25T03:30:26.824759 + 00:00 app [web.1]:文件/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py,第152行,__init__
2013-08-25T03: 30:26.824759 + 00:00 app [web.1]:文件/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py,第48行_setup
2013-08-25T03:30:26.824759 + 00:00 app [web.1]:self._wrapped =设置(settings_module)
2013-08-25T03:30:26.824759 + 00:00 app [web .1]:raise不正确配置(SECRET_KEY设置不能为空。)
2013-08-25T03:30:26.824759 + 00:00 app [web.1]:不正确的配置:SECRET_KEY设置不能空。
2013-08-25T03:30:26.825073 + 00:00 app [web.1]:2013-08-25 03:30:26 [7] [INFO]工人退出(pid:7)
2013-08-25T03:30:26.972807 + 00:00 app [web.1]:2013-08-25 03:30:26 [2] [INFO]关闭:Master
2013-08-25T03 :30:26.972807 + 00:00 app [web.1]:2013-08-25 03:30:26 [2] [INFO]原因:工人无法启动。
2013-08-25T03:30:27.576714 + 00:00 heroku [web.1]:进程退出状态0
2013-08-25T03:30:28.190167 + 00:00 heroku [web。 1]:进程退出状态3
2013-08-25T03:30:28.205185 + 00:00 heroku [web.1]:状态从开始变为崩溃
有没有人有这种事情的经验?
编辑:这是我的settings.py (假秘密):
#用于myblog项目的Django设置。
#注意:截至25/08/13,所有这些都配置为在Heroku上使用,需要
#使其更通用
DEBUG = False
TEMPLATE_DEBUG = False
SECRET_KEY ='ljw +(6 ^ 2fhoa ^ 1e _- $ - u(tk6 = vig * dw)r @ s640o ^ t2b)^ x * h'
ADMINS =(
#('Your Name','your_email@example.com'),
)
MANAGERS = ADMINS
#警告:被覆盖到
DATABASES = {
'default':{
'ENGINE':'django.db.backends.sqlite3',#添加'postgresql_psycopg2','mysql','sqlite3'或'oracle'
'NAME':'/home/mike/dev/myblog/myblog.db',#或使用sqlite3的数据库文件路径。
#以下设置不与sqlite3一起使用:
'USER':'',
'PASSWORD':'',
'HOST':'',#空本地主机通过域套接字或本地主机为127.0.0.1通过TCP。
'PORT':'',#设置为空字符串为默认值。
}
}
#对本网站有效的主机/域名;如果DEBUG为False,则需要
#请参阅https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
#本安装的本地时区。可以在这里找到选择:
#http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
#虽然并不是所有的操作系统都可以选择所有选项。
#在Windows环境中,必须将其设置为系统时区。
TIME_ZONE ='GMT'
#此安装的语言代码。所有选择可以在这里找到:
#http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE ='en-uk'
SITE_ID = 1
#如果将其设置为False,Django将进行一些优化,以便
#加载国际化机器。
USE_I18N = True
#如果将其设置为False,Django将不会根据当前语言环境格式设置日期,数字和
#日历。
USE_L10N = True
#如果将其设置为False,Django将不会使用时区感知数据时间。
USE_TZ = True
#将保存用户上传文件的目录的绝对文件系统路径。
#示例:/var/www/example.com/media/
MEDIA_ROOT ='/ app / media'
ZINNIA_UPLOAD_TO ='uploads'
#处理从MEDIA_ROOT提供的媒体的URL。确保使用
#尾部斜线。
#示例:http://example.com/media/,http://media.example.com/
MEDIA_URL ='/ media /'
#静态文件的绝对路径应该收集到。
#不要把任何东西放在这个目录下;在应用程序的static /子目录和STATICFILES_DIRS中存储静态文件
#。
#示例:/var/www/example.com/static/
STATICFILES_DIR =('zinna / static')
#静态根配置
STATIC_ROOT ='/ app'
#静态文件的URL前缀。
#示例:http://example.com/static/,http://static.example.com/
#STATIC_URL ='/ home / mike / dev / myblog / static /'
STATIC_URL ='/ static /'
#静态文件的附加位置
STATICFILES_DIRS =(
#将字符串放在这里,如/ home / html /静态或C:/ www / django / static
#即使在Windows上也可以使用正斜杠
#不要忘记使用绝对路径,而不是相对路径
'/ home / mike / dev / myblog / zinnia / static',
)
#知道如何在
#各个位置找到静态文件的finder类的列表。
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',
#取消注释下一行的简单点击保护:
#'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF ='myblog.urls'
#Django的runserver使用的WSGI应用程序的Python路径。
WSGI_APPLICATION ='myblog.wsgi.application'
TEMPLATE_DIRS =(
#将字符串放在这里,像/ home / html / django_templates或C:/ www / django / template
#总是使用正斜杠,甚至在Windows上
#不要忘记使用绝对路径,而不是相对路径
'templates',
)
TEMPLATE_CONTEXT_PROCESSORS =(
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors .request',
'django.core.context_processors.media',
'zinnia.context_processors.version',#可选
#'zinnia.context_processors.media',#trying to solve heroku这个
)的痛苦
INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib.contenttypes',
'django。 contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.st aticfiles',
#取消注释下一行以启用管理员:
'django.contrib.admin',
'django.contrib.comments',
#取消注释下一行启用管理员文档:
'django.contrib.admindocs',
'tagging',
'mptt',
'zinnia',
'blog',
)
#样本记录配置。通过此配置执行的唯一有形日志
#是在DEBUG = False时向每个HTTP 500错误发送电子邮件至
#的网站管理员。
#有关如何自定义日志配置的详细信息,请参阅http://docs.djangoproject.com/en/dev/topics/logging for
#。
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'
}
},
'logger':{
'django.request':{
'handlers':['mail_admins'],
'level':'ERROR',
'propagate'真的,
},
}
}
刚刚添加了,所以heroku可以工作:
import dj_database_url
DATABASES ['default' ] = dj_database_url.config()
#为request.is_secure()注册'X-Forwarded-Proto'标题
SECURE_PROXY_SSL_HEADER =('HT TP_X_FORWARDED_PROTO','https')
#允许所有主机头
ALLOWED_HOSTS = ['*']
解决方案问题在于你有一个陈旧的设置文件。确保从工作目录中清除所有
.pyc
文件(并将它们添加到.gitignore
)。
此外,您的静态文件还有无效路径
/ home / mike / dev / myblog / zinnia / static',
您应该阅读这篇文章,介绍如何为heroku上的静态资产设置django。 p>Sometimes when I push to heroku I get a message saying:
Application Error An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the application owner, check your logs for details.
I then run the command
$ heroku restart
a few times and its suddenly working fine again.
The error message from heroku logs is very long, here is a snippet from the bottom:
2013-08-25T03:30:26.824149+00:00 app[web.1]: self._setup(name) 2013-08-25T03:30:26.824453+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__ 2013-08-25T03:30:26.824453+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE) 2013-08-25T03:30:26.824453+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module 2013-08-25T03:30:26.824453+00:00 app[web.1]: self._wrapped = Settings(settings_module) 2013-08-25T03:30:26.824453+00:00 app[web.1]: __import__(name) 2013-08-25T03:30:26.824453+00:00 app[web.1]: File "/app/zinnia/settings.py", line 5, in <module> 2013-08-25T03:30:26.824453+00:00 app[web.1]: ('http://django-blog-zinnia.com/xmlrpc/',)) 2013-08-25T03:30:26.824453+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ 2013-08-25T03:30:26.824453+00:00 app[web.1]: self._setup(name) 2013-08-25T03:30:26.824759+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 152, in __init__ 2013-08-25T03:30:26.824759+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup 2013-08-25T03:30:26.824759+00:00 app[web.1]: self._wrapped = Settings(settings_module) 2013-08-25T03:30:26.824759+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") 2013-08-25T03:30:26.824759+00:00 app[web.1]: ImproperlyConfigured: The SECRET_KEY setting must not be empty. 2013-08-25T03:30:26.825073+00:00 app[web.1]: 2013-08-25 03:30:26 [7] [INFO] Worker exiting (pid: 7) 2013-08-25T03:30:26.972807+00:00 app[web.1]: 2013-08-25 03:30:26 [2] [INFO] Shutting down: Master 2013-08-25T03:30:26.972807+00:00 app[web.1]: 2013-08-25 03:30:26 [2] [INFO] Reason: Worker failed to boot. 2013-08-25T03:30:27.576714+00:00 heroku[web.1]: Process exited with status 0 2013-08-25T03:30:28.190167+00:00 heroku[web.1]: Process exited with status 3 2013-08-25T03:30:28.205185+00:00 heroku[web.1]: State changed from starting to crashed
Does anyone have experience of this sort of thing?
EDIT: Here are my settings.py (fake SECRET):
# Django settings for myblog project. #Note: as of 25/08/13 all this is configured for use on Heroku, need #to make it more generic DEBUG = False TEMPLATE_DEBUG = False SECRET_KEY = 'ljw+(6^2fhoa^1e_-$-u(tk6=vig*dw)r@s640o^t2b)^x*(^h' ADMINS = ( # ('Your Name', 'your_email@example.com'), ) MANAGERS = ADMINS #Warning:being overriden towards the end DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': '/home/mike/dev/myblog/myblog.db', # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': '', 'PASSWORD': '', 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '', # Set to empty string for default. } } # 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 = 'GMT' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-uk' 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 = '/app/media' ZINNIA_UPLOAD_TO='uploads' # 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 = '/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/" STATICFILES_DIR = ('zinna/static') # Static root configuration STATIC_ROOT = '/app' # URL prefix for static files. # Example: "http://example.com/static/", "http://static.example.com/" #STATIC_URL = '/home/mike/dev/myblog/static/' 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. '/home/mike/dev/myblog/zinnia/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', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # 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 = 'myblog.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'myblog.wsgi.application' 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. 'templates', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.i18n', 'django.core.context_processors.request', 'django.core.context_processors.media', 'zinnia.context_processors.version', # Optional # 'zinnia.context_processors.media', #trying to solve heroku pain with this ) 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', 'django.contrib.comments', # Uncomment the next line to enable admin documentation: 'django.contrib.admindocs', 'tagging', 'mptt', 'zinnia', 'blog', ) # 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, }, } } #added just now so heroku can work: import dj_database_url DATABASES['default'] = dj_database_url.config() # Honor the 'X-Forwarded-Proto' header for request.is_secure() SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # Allow all host headers ALLOWED_HOSTS = ['*']
解决方案The problem is you have a stale settings file somewhere. Make sure you purge all
.pyc
files from your working directory (and add them to.gitignore
).In addition you have invalid paths
/home/mike/dev/myblog/zinnia/static',
for your static files; you should read this article that explains how to setup django for static assets on heroku.这篇关于Heroku和Django随机崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!