当我在我的TEMPLATE_CONTEXT_PROCESSORS中包含django.core.context_processors.request时,除了django admin之外,我无法在我的网站上打开任何页面。
我收到BadHeaderError(标题值不能包含换行符)。
示例视图:
def home(request):
return render_to_response(
'index.html',
{},
content_type=RequestContext(request)
)
如果我从模板上下文处理器中删除它,一切都很好。
堆栈跟踪: / connor /
中的BadHeaderError`Header values can't contain newlines (got "[{'False': False, 'None': None, 'True': True}, {u'csrf_token': <django.utils.functional.__proxy__ object at 0x7fceb2bff390>}, {'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7fceb2bff4d0>, 'user': <SimpleLazyObject: <function <lambda> at 0x7fceb347ec08>>}, {}, {u'LANGUAGES': (('af', 'Afrikaans'), ('ar', 'Arabic'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('el', 'Greek'), ('en', 'English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy-nl', 'Frisian'), ('ga', 'Irish'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hu', 'Hungarian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmal'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('vi', 'Vietnamese'), ('zh-cn', 'Simplified Chinese'), ('zh-tw', 'Traditional Chinese')), u'LANGUAGE_BIDI': False, u'LANGUAGE_CODE': 'en-us'}, {u'MEDIA_URL': ''}, {u'STATIC_URL': '/static/'}, {u'TIME_ZONE': 'UTC'}, {'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x7fceb348cc10>}, {u'request': <WSGIRequest\npath:/connor/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {}>,\nCOOKIES:{'csrftoken': '4tXkvoGuR0iPoK2yrA1XIzslr6shHwLd',\n 'sessionid': '8lswc66fcc383v95uk8iaizrry44t0qt'},\nMETA:{'CLASSPATH': '/home/connor/Documents/pycharm-3.4.1/bin/../lib/bootstrap.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/extensions.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/util.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/jdom.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/log4j.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/trove4j.jar:/home/connor/Documents/pycharm-3.4.1/bin/../lib/jna.jar',\n 'CLUTTER_IM_MODULE': 'xim',\n 'COMPIZ_BIN_PATH': '/usr/bin/',\n 'COMPIZ_CONFIG_PROFILE': 'ubuntu',\n 'CONTENT_LENGTH': '',\n 'CONTENT_TYPE': 'text/plain',\n u'CSRF_COOKIE': u'4tXkvoGuR0iPoK2yrA1XIzslr6shHwLd',\n 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-D0GD7R6pgD',\n 'DEFAULTS_PATH': '/usr/share/gconf/ubuntu.default.path',\n 'DESKTOP_SESSION': 'ubuntu',\n 'DISPLAY': ':0',\n 'DJANGO_SETTINGS_MODULE': 'hellodjango.settings',\n 'GATEWAY_INTERFACE': 'CGI/1.1',\n 'GDMSESSION': 'ubuntu',\n 'GDM_LANG': 'en_GB',\n 'GIO_LAUNCHED_DESKTOP_FILE': '/home/connor/.local/share/applications/jetbrains-pycharm.desktop',\n 'GIO_LAUNCHED_DESKTOP_FILE_PID': '2221',\n 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated',\n 'GNOME_KEYRING_CONTROL': '/run/user/1000/keyring-5Y1bXE',\n 'GPG_AGENT_INFO': '/run/user/1000/keyring-5Y1bXE/gpg:0:1',\n 'GTK_IM_MODULE': 'ibus',\n 'GTK_MODULES': 'overlay-scrollbar:unity-gtk-module',\n 'HOME': '/home/connor',\n 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',\n 'HTTP_ACCEPT_LANGUAGE': 'en-gb,en;q=0.5',\n 'HTTP_CACHE_CONTROL': 'max-age=0',\n 'HTTP_CONNECTION': 'keep-alive',\n 'HTTP_COOKIE': 'csrftoken=4tXkvoGuR0iPoK2yrA1XIzslr6shHwLd; sessionid=8lswc66fcc383v95uk8iaizrry44t0qt',\n 'HTTP_HOST': 'localhost:8000',\n 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0',\n 'IM_CONFIG_PHASE': '1',\n 'INSTANCE': '',\n 'JOB': 'dbus',\n 'LANG': 'en_GB.UTF-8',\n 'LANGUAGE': 'en_GB:en',\n 'LD_LIBRARY_PATH': '/home/connor/Documents/pycharm-3.4.1/bin:',\n 'LOGNAME': 'connor',\n 'MANDATORY_PATH': '/usr/share/gconf/ubuntu.mandatory.path',\n 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/connor/development/hellodjango/venv/bin',\n 'PATH_INFO': u'/connor/',\n 'PWD': '/home/connor',\n 'PYCHARM_HOSTED': '1',\n 'PYTHONIOENCODING': 'UTF-8',\n 'PYTHONPATH': '/home/connor/development/hellodjango',\n 'PYTHONUNBUFFERED': '1',\n 'QT4_IM_MODULE': 'xim',\n 'QT_IM_MODULE': 'ibus',\n 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5',\n 'QUERY_STRING': '',\n 'REMOTE_ADDR': '127.0.0.1',\n 'REMOTE_HOST': '',\n 'REQUEST_METHOD': 'GET',\n 'RUN_MAIN': 'true',\n 'SCRIPT_NAME': u'',\n 'SELINUX_INIT': 'YES',\n 'SERVER_NAME': 'localhost',\n 'SERVER_PORT': '8000',\n 'SERVER_PROTOCOL': 'HTTP/1.1',\n 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.6',\n 'SESSION': 'ubuntu',\n 'SESSIONTYPE': 'gnome-session',\n 'SESSION_MANAGER': 'local/connor-VirtualBox:@/tmp/.ICE-unix/1321,unix/connor-VirtualBox:/tmp/.ICE-unix/1321',\n 'SHELL': '/bin/bash',\n 'SSH_AGENT_LAUNCHER': 'upstart',\n 'SSH_AGENT_PID': '1260',\n 'SSH_AUTH_SOCK': '/run/user/1000/keyring-5Y1bXE/ssh',\n 'TEXTDOMAIN': 'im-config',\n 'TEXTDOMAINDIR': '/usr/share/locale/',\n 'TZ': 'UTC',\n 'UBUNTU_MENUPROXY': '1',\n 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/1149',\n 'USER': 'connor',\n 'XAUTHORITY': '/home/connor/.Xauthority',\n 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg',\n 'XDG_CURRENT_DESKTOP': 'Unity',\n 'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/',\n 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/connor',\n 'XDG_MENU_PREFIX': 'gnome-',\n 'XDG_RUNTIME_DIR': '/run/user/1000',\n 'XDG_SEAT': 'seat0',\n 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0',\n 'XDG_SESSION_ID': 'c1',\n 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0',\n 'XDG_VTNR': '7',\n 'XMODIFIERS': '@im=ibus',\n 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fcebb9871e0>,\n 'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x7fceb8e26bb0>,\n 'wsgi.input': <socket._fileobject object at 0x7fceb8713a50>,\n 'wsgi.multiprocess': False,\n 'wsgi.multithread': True,\n 'wsgi.run_once': False,\n 'wsgi.url_scheme': 'http',\n 'wsgi.version': (1, 0)}>}]")
`
Exception Location: /home/connor/development/hellodjango/venv/local/lib/python2.7/site-packages/django/http/response.py in _convert_to_charset, line 174
Python Executable: /home/connor/development/hellodjango/venv/bin/python
Python Version: 2.7.6
Python Path:
['/home/connor/development/hellodjango',
'/home/connor/development/hellodjango',
'/home/connor/development/hellodjango/venv/lib/python2.7',
'/home/connor/development/hellodjango/venv/lib/python2.7/plat-x86_64-linux-gnu',
'/home/connor/development/hellodjango/venv/lib/python2.7/lib-tk',
'/home/connor/development/hellodjango/venv/lib/python2.7/lib-old',
'/home/connor/development/hellodjango/venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/connor/development/hellodjango/venv/local/lib/python2.7/site-packages']`