我试图让django-debug-toolbar启动并运行时遇到问题.我把所有的加入必要的信息INSTALLED_APPS,MIDDLEWARE_CLASSES和我的IP地址在INTERNAL_IPS元组.我已经运行了setup.py脚本,所有内容似乎都正常加载,因为我没有从django或apache获得任何错误.
然而,没有任何事情 - 任何页面上没有工具栏,有没有人见过这种行为?我错过了一些明显的东西吗
我的问题最初表现为一个相当普遍的"超出最大递归深度"错误ListView.在挖掘之后,我发现每次尝试加载相应页面时都会在dbtemplates中发现大量缓存命中.这促使我编写了自己的模板加载器,此时很明显Django load_template_source每次加载页面时都会调用六十九次.
为什么Django会load_template_source多次拨打电话?
visitor_index(db模板)
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ site.name }}</title>
</head>
<body id="home">
<pre>
Starting
{% for video in videos %}
{{ video.headline }}
{% endfor %}
</pre>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
urls.py
from django.conf.urls import include, url
from django.conf.urls.defaults import patterns
from videos.views import *
urlpatterns = patterns('',
url(r'^$', VisitorIndex.as_view(), name='index'),
)
Run Code Online (Sandbox Code Playgroud)
views.py
import logging
from django.views.generic import ListView
from videos.models import Video
logger = logging.getLogger(__name__)
class VisitorIndex(ListView):
context_object_name = 'videos'
template_name = 'visitor_index' …Run Code Online (Sandbox Code Playgroud) 我正在使用django-debug-toolbar(最新版本,v1.2.1),我在控制台中不断收到此错误:
Empty string passed to getElementById()
Run Code Online (Sandbox Code Playgroud)
对于jQuery中的这段代码(第2757行):
...
// HANDLE: $(#id)
} else {
elem = document.getElementById( match[2] );
...
Run Code Online (Sandbox Code Playgroud)
我单击的调试工具栏中的每个链接都会再次出现此警告.
当我注释掉我的主要jQuery源文件时,调试工具栏可以工作.此外,在Django管理员中,它工作正常,大概是因为Django管理员使用不同的方法来获取jQuery.
我试过@Carlton Gibson的答案,但这并没有解决我的问题.我也尝试过本地jQuery,从CDN和一些不同的版本到无济于事......
我尝试过不同版本的jQuery并使用文档中提供的所有可能设置django-debug-toolbar.我被困住了,我真的很喜欢这个工具,希望它适合我.
编辑
由于我收到了一些额外的评论和答案,我想我会做一个编辑来解释我尝试过的内容.我没有成功地尝试了所有建议.但是,目前,我在另一篇关于RequireJS的文章中看到了另一个错误django-debug-toolbar:
GET http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js [HTTP/1.1 304 Not Modified 133ms]
ReferenceError: jQuery is not defined localhost:8000:119
TypeError: djdt is undefined toolbar.js:297
Empty string passed to getElementById()
Run Code Online (Sandbox Code Playgroud)
即使加载了jQuery并且我告诉django-debug-toolbar我使用我的版本(with DEBUG_TOOLBAR_CONFIG = { 'JQUERY_URL': '', }),我仍然会收到错误并且DjDT无效.这一次,它甚至没有出现因为TypeError.
编辑
这base.html是导入JS 的块.请记住,这是一个快照,它已经发生了很大的变化.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" defer></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js" defer></script>
Run Code Online (Sandbox Code Playgroud)
我还有一个我正在使用的返回顶部小部件可能是罪魁祸首.由于我一直在使用这段代码,我从未想过这是一个问题,但现在我怀疑它可能是.此外,由于错误与 …
它在过去几天工作,但现在工具栏上的所有链接都只是#
<li class="djDebugPanelButton active">
<input type="checkbox" data-cookie="djdtSQLPanel" checked="checked" title="Disable for next and successive requests">
<a href="#" title="SQL queries from 1 connection" class="SQLPanel">SQL<br><small>215 queries in 174.10ms</small></a>
</li>
Run Code Online (Sandbox Code Playgroud)
我明确地设置了这样说:http: //django-debug-toolbar.readthedocs.org/en/1.0/installation.html#explicit-setup
我没有得到djdt命名空间问题,实际上我没有任何错误,除了404我试图查看其中一个面板.....
我安装了 django 1.9 和 django-debug-toolbar==1.3.0 。这是我的settings.py内容
# debug_toolbar settings
if DEBUG:
INTERNAL_IPS = ('127.0.0.1',)
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
INSTALLED_APPS += (
'debug_toolbar',
)
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
]
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
}
Run Code Online (Sandbox Code Playgroud)
我已验证 DEBUG 设置为 True。运行服务器时,我收到以下错误 -
django.core.exceptions.ImproperlyConfigured: Error importing debug panel debug_toolbar.panels.versions: "cannot import name linebreak_iter"
Run Code Online (Sandbox Code Playgroud)
整个堆栈跟踪可以在这里找到 - https://gist.github.com/anonymous/7a48e7c24d530118e5dfc0a75b982be2
出了什么问题?TIA。
我正在使用 docker,调试工具栏出现以下错误:
BaseConnectionHandler.all() got an unexpected keyword argument 'initialized_only'
Run Code Online (Sandbox Code Playgroud)
我在settings.py文件中编写了以下代码:
if DEBUG:
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INSTALLED_APPS += [
'debug_toolbar',
]
import os
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
Run Code Online (Sandbox Code Playgroud)
我在 urls.py 文件中编写了以下代码:
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
]
Run Code Online (Sandbox Code Playgroud) 我试图安装Django Panels并遇到错误.我使用pip安装 - pip install django-debug-toolbar- 它似乎没问题.但是当我将它添加到我的项目中时:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.flatpages',
'coltrane',
'markdown',
'debug_toolbar',
)
Run Code Online (Sandbox Code Playgroud)
然后运行python manage.py syncdb 得到以下错误:
python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.7.dev20140121103749-py2.7.egg/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.7.dev20140121103749-py2.7.egg/django/core/management/__init__.py", line 391, in execute
django.setup()
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.7.dev20140121103749-py2.7.egg/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.7.dev20140121103749-py2.7.egg/django/apps/registry.py", line 105, in populate
app_config.import_models(all_models)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.7.dev20140121103749-py2.7.egg/django/apps/base.py", line 160, in import_models
self.models_module = import_module(models_module_name)
File …Run Code Online (Sandbox Code Playgroud) 我实际上是在一个Django网站上工作,使用django调试工具栏,在数字海洋小dropplet.这一切都适用于Postgresql,Django,gunicorn和Nginx.
让我烦恼的是,渲染时间约为2.5秒,而且大部分时间都与用户CPU时间有关.
Resource Value
User CPU time 2271.395 msec
System CPU time 86.142 msec
Total CPU time 2357.537 msec
Elapsed time 2483.655 msec
Context switches 8 voluntary, 469 involuntary
Browser Chronology
domainLookup 0 (+0)
connect 0 (+0)
request 3 (+-1419272753107)
response 5653 (+-1419272758757)
domLoading 5669 (+-1419272758773)
domInteractive -1419272753104
domContentLoadedEvent -1419272753104 (+0)
loadEvent -1419272753104 (+0)
Run Code Online (Sandbox Code Playgroud)
所以,我想提高速度,我设置了一个快速的数字海洋液滴(最大的一个),时间看起来一样.据我所知,最大的Droplet主要意味着更多的CPU核心,因此,更多的同时请求.
但问题是那两个:
Django调试工具栏是一个很好的工具,可以分析缓慢的SQL查询-等等。我可以在Django应用中针对GET响应执行此操作。我的问题是:如何配置(和优化)我的POST响应?
我正在构建 BlogApp 并且正在尝试运行Django-Debug-Toolbar但它没有显示。我看过很多答案,但没有一个对我有用。
我已经按照文档正确安装了
我添加了installed apps,middlewares和urls以及collecstatic。但当我进入浏览器时仍然没有显示。
设置.py
if DEBUG:
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INSTALLED_APPS += [
'debug_toolbar',
]
INTERNAL_IPS = ['127.0.0.1', ]
# this is the main reason for not showing up the toolbar
import mimetypes
mimetypes.add_type("application/javascript", ".js", True)
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
}
Run Code Online (Sandbox Code Playgroud)
urls.py
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
]
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
先感谢您