2014-03-31 55 views
2

我试着去建立瓶调试工具栏,但得到以下错误...瓶调试工具栏

todo.py

import sqlite3 
import bottle 
from bottle_debugtoolbar import DebugToolbarPlugin 
from bottle import route, run, debug, template, request, error, PasteServer 

config = {'DEBUG_TB_ENABLED': True, 
      'DEBUG_TB_INTERCEPT_REDIRECTS':True 
       } 

plugin = DebugToolbarPlugin(config) 
bottle.install(plugin) 

错误

Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 862, in _handle 
    return route.call(**args) 
    File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 1727, in wrapper 
    rv = callback(*a, **ka) 
    File "/usr/local/lib/python2.7/dist-packages/bottle_debugtoolbar/__init__.py", line 75, in wrapper 
    return self.process_response(content) 
    File "/usr/local/lib/python2.7/dist-packages/bottle_debugtoolbar/__init__.py", line 135, in process_response 
    and bottle.response.headers['content-type'].startswith('text/html') 
    File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 1930, in __getitem__ 
    def __getitem__(self, key): return self.dict[_hkey(key)][-1] 
KeyError: 'Content-Type' 

回答

1

bottle-debugtoolbar使一个assumptionContent-type响应标题已设置。

只需设置使用bottle.response响应内容类型:

from bottle import response 
... 

@bottle.route('/') 
def index(): 
    response.headers['Content-Type'] = 'text/html; charset=UTF-8' 
    ... 

UPD:

这里有一个简单的工作示例:

import bottle 
from bottle_debugtoolbar import DebugToolbarPlugin 
from bottle import response 


config = { 
    'DEBUG_TB_ENABLED': True, 
    'DEBUG_TB_INTERCEPT_REDIRECTS': True, 
} 
plugin = DebugToolbarPlugin(config) 
bottle.install(plugin) 


@bottle.route('/') 
def guestbook_index(): 
    response.headers['Content-Type'] = 'text/html; charset=UTF-8' 
    return '<html><body>Hello, world</body></html>' 

bottle.debug(True) 
bottle.run(host='localhost', port=8082) 

希望有所帮助。

+0

:谢谢......它的工作..但现在我没有看到工具栏? – user1050619

+0

@ user1050619 hm,查看答案的“UPD”部分。这是我用来测试的。 – alecxe

+0

非常感谢..它的工作..我没有在我的html页面中的标记......一旦我添加,我看到它正在显示...... – user1050619