我在AWS Elastic Beanstalk上运行Django应用程序,但Django调试工具栏导致以下错误:
Traceback (most recent call last):
File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 235, in get_response
response = middleware_method(request, response)
File "/opt/python/run/venv/lib/python3.4/site-packages/debug_toolbar/middleware.py", line 123, in process_response
response.content = insert_before.join(bits)
File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/response.py", line 315, in content
value = self.make_bytes(value)
File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/response.py", line 235, in make_bytes
return bytes(value.encode(self.charset))
UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcc3' in position 142917: surrogates not allowed
我在本地没有遇到此问题,或者在我自己设置nginx和gunicorn的AWS EC2实例上运行我的django应用程序时。关于Elastic Beanstalk的事情?也许这是阿帕奇?
有关我的配置的一些细节:
版本
在本地以及AWS EBS上
Python 3.4.3
Django 1.9.7
Django Toolbar 1.5
Django设置
以下是我激活工具栏
的django设置INSTALLED_APPS = [
'compare.apps.CompareConfig',
'search.apps.SearchConfig',
'profile.apps.ProfileConfig',
'common.apps.CommonConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_toolbar',
]
(我尝试在已安装的应用列表中进一步移动django_toolbar
,但它没有帮助)
MIDDLEWARE_CLASSES = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'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',
]
DEBUG_TOOLBAR_PATCH_SETTINGS = False
def custom_show_toolbar(request):
return True # Always show toolbar, for example purposes only.
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
在我的root url conf文件中我有
urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))]
还有一些其他的SO(现在找不到链接)提到了将utf-8
添加到其中一种语言或USE_***
参数但我尝试了但并没有帮助 - 但也许我也没有正确地做到这一点。
我非常喜欢Django调试工具栏,非常感谢能够解决这个问题。
有什么想法吗?
谢谢!